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'
Create a type that represents an array of the given type and length. The array's length and the
Arrayprototype methods that manipulate its length are excluded in the resulting type.Please participate in this issue if you want to have a similar type built into TypeScript.
Use-cases:
0 | 1 | 2 | 3 | 4from the keys of such a type) without having to resort to recursive types.Note: This type does not prevent out-of-bounds access. Prefer
ReadonlyTupleunless you need mutability.