.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / type-fest / source / fixed-length-array.d.ts
1 /**
2 Methods to exclude.
3 */
4 type ArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift';
5
6 /**
7 Create a type that represents an array of the given type and length. The array's length and the `Array` prototype methods that manipulate its length are excluded in the resulting type.
8
9 Please participate in [this issue](https://github.com/microsoft/TypeScript/issues/26223) if you want to have a similiar type built into TypeScript.
10
11 Use-cases:
12 - Declaring fixed-length tuples or arrays with a large number of items.
13 - Creating a range union (for example, `0 | 1 | 2 | 3 | 4` from the keys of such a type) without having to resort to recursive types.
14 - Creating an array of coordinates with a static length, for example, length of 3 for a 3D vector.
15
16 @example
17 ```
18 import {FixedLengthArray} from 'type-fest';
19
20 type FencingTeam = FixedLengthArray<string, 3>;
21
22 const guestFencingTeam: FencingTeam = ['Josh', 'Michael', 'Robert'];
23
24 const homeFencingTeam: FencingTeam = ['George', 'John'];
25 //=> error TS2322: Type string[] is not assignable to type 'FencingTeam'
26
27 guestFencingTeam.push('Sam');
28 //=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
29 ```
30 */
31 export type FixedLengthArray<Element, Length extends number, ArrayPrototype = [Element, ...Element[]]> = Pick<
32         ArrayPrototype,
33         Exclude<keyof ArrayPrototype, ArrayLengthMutationKeys>
34 > & {
35         [index: number]: Element;
36         [Symbol.iterator]: () => IterableIterator<Element>;
37         readonly length: Length;
38 };