Reputation: 1552
I know TypeScript has a keyof
keyword which yields the type of permitted property names for a given type. Is there also something like a propertyof
which will get me the values of the keys of a given type? Specifically, I am wondering if there is a shorter way of doing
type Propertyof<T> = T[keyof T]
Upvotes: 2
Views: 846
Reputation: 249556
The way you discovered is the way to get the property value types:
type Propertyof<T> = T[keyof T]
There is no reason to have more features in the language then necessary, propertyof T
would not be shorter, in fact as jcalz points out it is actually 2 characters longer.
Upvotes: 4