-
-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy patharray-indices.d.ts
More file actions
25 lines (17 loc) · 737 Bytes
/
array-indices.d.ts
File metadata and controls
25 lines (17 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
Provides valid indices for a constant array or tuple.
Use-case: This type is useful when working with constant arrays or tuples and you want to enforce type-safety for accessing elements by their indices.
@example
```
import type {ArrayIndices, ArrayValues} from 'type-fest';
const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] as const;
type Weekday = ArrayIndices<typeof weekdays>;
type WeekdayName = ArrayValues<typeof weekdays>;
const getWeekdayName = (day: Weekday): WeekdayName => weekdays[day];
```
@see {@link ArrayValues}
@category Array
*/
export type ArrayIndices<Element extends readonly unknown[]> =
Exclude<Partial<Element>['length'], Element['length']>;
export {};