It's a common question and not many know how to do it: https://stackoverflow.com/a/49286056/64949
type ValueOf<T> = T[keyof T];
type Foo = {a: string, b: number};
type ValueOfFoo = ValueOf<Foo>;
// string | number
The code is simple, but remembering the syntax is not. It would also be nice to have it as few know it's possible at all.
Real-world use-case: https://github.com/goodmind/FlowDefinitelyTyped/blob/333ce3a4273848326bfc43827eb4e7aa9a9d7441/types/react-native-vector-icons/FontAwesome5.d.ts
We could also consider instead adding a more powerful version that optionally supports picking the keys to get value from:
type ValueOf<T, K extends keyof T = keyof T> = T[K];
type Foo = {a: string, b: number: c: boolean};
type ValueOfFoo = ValueOf<Foo, 'a' | 'c'>;
// string | boolean
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too