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

Unexpected "An index signature parameter type must be 'string' or 'number'." error with string union type. #8711

Closed
Strate opened this issue May 20, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@Strate
Copy link

Strate commented May 20, 2016

TypeScript Version:

1.8.10

Code

type StringEnum = "one" | "two"

interface IndexedObject {
  [index: StringEnum]: boolean
}

Expected behavior:
No error

Actual behavior:
error TS1023: An index signature parameter type must be 'string' or 'number'.

@evansb
Copy link
Contributor

evansb commented May 20, 2016

Reproducible in latest master.

At the moment only string or number keyword can be used as index parameter type, so a simpler type alias below also fails.

type StringEnum = string;

interface IndexedObject {
  [index: StringEnum]: boolean
}

Edit: This is intended behaviour, see the grammar of Index Signatures

@Strate
Copy link
Author

Strate commented May 20, 2016

This is intended behaviour, see the grammar of Index Signatures

I think that Index Signatures could be extended without regression

@sandersn
Copy link
Member

sandersn commented May 20, 2016

Duplicate of #8336, #5683, #2491, and #7656. Some of these have good discussion. This is a popular request.

@sandersn sandersn added the Duplicate An existing issue was already created label May 20, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants