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

Union types are not allowed in indexers #1715

Closed
jods4 opened this issue Jan 18, 2015 · 1 comment · Fixed by #1765
Closed

Union types are not allowed in indexers #1715

jods4 opened this issue Jan 18, 2015 · 1 comment · Fixed by #1765
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@jods4
Copy link

jods4 commented Jan 18, 2015

I have declared function getter(key: string|number).
Inside I try to do var x = someObject[key]
I get a TS error saying "An index expression argument must be of type 'string', 'number' or 'any'.
Obviously key satisfies this constraint as it is either a string or a number. But I guess the TS compiler does hard type equality checks in this case.

@ahejlsberg
Copy link
Member

You're right, we'll fix that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants