-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingFix AvailableA PR has been opened for this issueA PR has been opened for this issueHelp WantedYou can do thisYou can do this
Milestone
Description
TypeScript Version: Playground version
Code
type Foo = {
[P in 'a' | 'b']: any;
}
interface Bar {
[P in 'a' | 'b']: any;
}
Expected behavior:
One of these two options:
- No errors at all, and roughly equivalent semantics.
- A parse error, in case this should specifically be disallowed (to align with classes, since
[foo in bar]
is required to be a valid class property/method name).
Actual behavior:
A mess of type errors because [P in T]: any
is parsed in interfaces as a computed symbol property with key P in T
(i.e. a boolean). In kind, I get three sets of type errors:
-
For
P
:- A computed property name in an interface must directly refer to a built-in symbol.
- Cannot find name 'P'.
- The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
-
For
'a' | 'b'
:- A computed property name in an interface must directly refer to a built-in symbol.
- The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter.
- The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
aluanhaddad, sean-vieira, jcalz, yortus, c69 and 1 more
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingFix AvailableA PR has been opened for this issueA PR has been opened for this issueHelp WantedYou can do thisYou can do this