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

Support union type as index signature parameter type. #2611

Closed
saml opened this issue Apr 3, 2015 · 1 comment
Closed

Support union type as index signature parameter type. #2611

saml opened this issue Apr 3, 2015 · 1 comment
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@saml
Copy link

saml commented Apr 3, 2015

Given:

interface Foo {
  [key: string | number]: boolean;
}

I get

bleh.ts(2,4): error TS1023: An index signature parameter type must be 'string' or 'number'.

A workaround is:

interface Foo {
  [key: number]: boolean;
  [key: string]: boolean;
}

But, I need to match up the type of value, boolean. Since it's a repetition, it could be useful to programmers to specify index signature parameter type as string, number, string | number, or number | string.

@danquirk
Copy link
Member

danquirk commented Apr 3, 2015

If your string and number indexers are the same then you don't need to do this. A string indexer subsumes the numeric indexer. If there's something more involved for indexer types you needed maybe #2049 is relevant.

@danquirk danquirk closed this as completed Apr 3, 2015
@danquirk danquirk added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Apr 3, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

No branches or pull requests

2 participants