Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression - able to use union containing non-indexing type as index #26714

Closed
RyanCavanaugh opened this issue Aug 28, 2018 · 3 comments
Closed
Assignees
Labels
Bug A bug in TypeScript

Comments

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Aug 28, 2018

TypeScript Version: master at bd40583

Search Terms: array index union error

Code

declare const arr1: (string | string[])[];
declare const arr2: number[];
const j = arr2[arr1[0]];

Expected behavior: Error - Type string[] cannot be used as an index type

Actual behavior: No error

Playground Link: Link

Related Issues: Regressed during fix of #26409 (edit: #26281 ?)

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 28, 2018
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.1 milestone Aug 28, 2018
@RyanCavanaugh
Copy link
Member Author

Ref #26712 & #26698

@ahejlsberg
Copy link
Member

ahejlsberg commented Aug 28, 2018 via email

@weswigham
Copy link
Member

Righto, so this is a bit interesting. Since the index distributes to number[string] | number[string[]] and noImplicitAny is off, number[string] silently becomes any and then we don't bother to check number[string[]]. I can fix it so we still do the validity check even if we won't use the type; just thought it was interesting~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants