Sha256: 31073e7d0e51f33b1456ff2ab7f06546c95e24e11c29d5b39a634bc51f86d914

Contents?: true

Size: 1.59 KB

Versions: 28

Compression:

Stored size: 1.59 KB

Contents

/**
Methods to exclude.
*/
type ArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift';

/**
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.

Please participate in [this issue](https://github.com/microsoft/TypeScript/issues/26223) if you want to have a similar type built into TypeScript.

Use-cases:
- Declaring fixed-length tuples or arrays with a large number of items.
- 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.
- Creating an array of coordinates with a static length, for example, length of 3 for a 3D vector.

Note: This type does not prevent out-of-bounds access. Prefer `ReadonlyTuple` unless you need mutability.

@example
```
import type {FixedLengthArray} from 'type-fest';

type FencingTeam = FixedLengthArray<string, 3>;

const guestFencingTeam: FencingTeam = ['Josh', 'Michael', 'Robert'];

const homeFencingTeam: FencingTeam = ['George', 'John'];
//=> error TS2322: Type string[] is not assignable to type 'FencingTeam'

guestFencingTeam.push('Sam');
//=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
```

@category Array
@see ReadonlyTuple
*/
export type FixedLengthArray<Element, Length extends number, ArrayPrototype = [Element, ...Element[]]> = Pick<
ArrayPrototype,
Exclude<keyof ArrayPrototype, ArrayLengthMutationKeys>
> & {
	[index: number]: Element;
	[Symbol.iterator]: () => IterableIterator<Element>;
	readonly length: Length;
};

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.25 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.24 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.23 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.22 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.21 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.20 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.19 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.18 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.17 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.16 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.15 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.14 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.13 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.12 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.11 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.10 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.9 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.8 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts
clapton-0.0.7 lib/clapton/javascripts/node_modules/type-fest/source/fixed-length-array.d.ts