-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
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
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug