Closed
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.