feihcsim
feihcsim

Reputation: 1552

TypeScript propertyof

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

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

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

Related Questions