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

Cannot use valid union type as a map's key #27219

Closed
Tyriar opened this issue Sep 19, 2018 · 2 comments
Closed

Cannot use valid union type as a map's key #27219

Tyriar opened this issue Sep 19, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@Tyriar
Copy link
Member

Tyriar commented Sep 19, 2018

TypeScript Version: 3.0

Search Terms:

map
union type
string | number

Code

const m: { [key: string | number]: any };

class C<K extends string | number> {
    private _m: { [key: K]: any };
}

Expected behavior:

It compiles.

Actual behavior:

An index signature parameter type must be 'string' or 'number'.
(parameter) key: string | number

Playground Link: http://www.typescriptlang.org/play/#src=const%20m%3A%20%7B%20%5Bkey%3A%20string%20%7C%20number%5D%3A%20any%20%7D%3B%0D%0A%0D%0Aclass%20C%3CK%20extends%20string%20%7C%20number%3E%20%7B%0D%0A%20%20%20%20private%20_m%3A%20%7B%20%5Bkey%3A%20K%5D%3A%20any%20%7D%3B%0D%0A%7D

@jack-williams
Copy link
Collaborator

Probably fixed by #26797

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Sep 24, 2018
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants