type-fest
Version:
A collection of essential TypeScript types
25 lines (17 loc) • 730 B
TypeScript
/**
Create a union of the given object's values, and optionally specify which keys to get the values from.
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
@example
```
import type {ValueOf} from 'type-fest';
type A = ValueOf<{id: number; name: string; active: boolean}>;
//=> number | string | boolean
type B = ValueOf<{id: number; name: string; active: boolean}, 'name'>;
//=> string
type C = ValueOf<{id: number; name: string; active: boolean}, 'id' | 'name'>;
//=> number | string
```
@category Object
*/
export type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
export {};