Closed
Description
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
.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
danquirk commentedon 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.