Closed
Description
Revised feature request: Please allow typeof
in mapped types:
Given a type like this:
type Enum<TEnum> = {
[TName in keyof typeof TEnum]: TEnum[TName]
}
I want to write
type Schema<TObject> = {
[TName in keyof TObject]: Enum<typeof (TObject[TName])>
}
This way, given the property declared as foo: SomeEnum
, the mapped type would produce foo: Enum<typeof SomeEnum>
, which would then match actual property foo: SomeEnum
.
TObject[TName]
is a value, so typeof
should apply. However, this currently gives a syntax error.
Removing the parentheses complains (correctly) that TObject
itself is a type, not a value.
TypeScript Version: 2.7.0
Search Terms: typeof keyof generic