Skip to content

ValueOf type ​

The union of the value types of an object type, such as a const object used as an enum.

ts
import type { ValueOf } from 'utils';

Signature ​

ts
export type ValueOf<T> = T[keyof T];

Parameters ​

NameDescription
TThe object type.

Example ​

ts
const STATUS = { idle: 'idle', running: 'running' } as const;
type Status = ValueOf<typeof STATUS>; // 'idle' | 'running'

Tests ​

Line coverage: 0 %.

Source ​

src/types/value-of.ts (on GitHub)

Source code
ts
/**
 * The union of the value types of an object type, such as a `const` object used as an enum.
 *
 * @template T - The object type.
 * @example
 * const STATUS = { idle: 'idle', running: 'running' } as const;
 * type Status = ValueOf<typeof STATUS>; // 'idle' | 'running'
 */
export type ValueOf<T> = T[keyof T];

Keywords: value, of, types, type

Generated from the JSDoc of the sources.