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

Allow index signature parameter type to be String Literal Type and enum member. #8921

Closed
RainingChain opened this issue Jun 1, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@RainingChain
Copy link

At the moment, index signature parameter type must be string or number.
Now that Typescript supports String literal types, it would be great if it could be used for index signature parameter type as well.

For example:

type MyString = "a" | "b" | "c";

var MyMap:{[id:MyString] : number} = {};
MyMap["a"] = 1; // valid
MyMap["asd"] = 2;   //invalid

It would be also useful if it could also work with Enums. For example:

enum MyEnum {
    a = <any>"a",
    b = <any>"b",
    c = <any>"c",
    d = <any>"d",
}

var MyMap:{[id:MyEnum] : number} = {};
MyMap[MyEnum.a] = 1; // valid
MyMap["asd"] = 2;   //invalid

var MyMap:{[id:MyEnum] : number} = {
    [MyEnum.a]:1,   // valid
    "asdas":2,  //invalid
}
@Arnavion
Copy link
Contributor

Arnavion commented Jun 2, 2016

Duplicate of #2491 and #5683

@mhegazy mhegazy closed this as completed Jun 2, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Jun 2, 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