UNPKG

648 BTypeScriptView Raw
1/**
2Provides all values for a constant array or tuple.
3
4Use-case: This type is useful when working with constant arrays or tuples and you want to enforce type-safety with their values.
5
6@example
7```
8import type {ArrayValues, ArrayIndices} from 'type-fest';
9
10const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] as const;
11
12type WeekdayName = ArrayValues<typeof weekdays>;
13type Weekday = ArrayIndices<typeof weekdays>;
14
15const getWeekdayName = (day: Weekday): WeekdayName => weekdays[day];
16```
17
18@see {@link ArrayIndices}
19
20@category Array
21*/
22export type ArrayValues<T extends readonly unknown[]> = T[number];