-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: enumEnums and their associated types/valuesEnums and their associated types/valuesGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green light
Milestone
Description
TypeScript Version: 2.9.2
Search Terms: computed property name
Code
enum Type {
Foo = 'foo',
'3x14' = '3x14'
}
type TypeMap = {
[Type.Foo]: any
[Type['3x14']]: any
}Expected behavior:
Type['3x14'] to be usable as a computed key in a type definition.
Actual behavior:
A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.
This is the case even for Type.Foo if it's written as Type['Foo'] instead; so it seems there is some early bailout when the bracket operator is involved. For certain key names it may not be possible to write them without resorting to brackets, like a name that starts with a digit.
Playground Link: Link
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: enumEnums and their associated types/valuesEnums and their associated types/valuesGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green light