type alias ValueOf

This is a utility type that allows you to get the values from an object or a list.

Examples

Example 1

const MyEnum = { foo: 'bar', another: 'baz' } as const;
const MyList = ['apple', 'banana', 'orange'] as const;

function example(param: ValueOf<typeof MyEnum>): void {
  // param would be: "bar" | "baz"
}

function example2(param: ValueOf<typeof MyList): void {
  // param would be: "apple" | "banana" | "orange"
}

Type Parameters

Definition

T extends Readonly<unknown[]> ? T[number] : T[keyof T]

Usage

import { type ValueOf } from ".";