type-fest/source/array-tail.d.ts
Fernando Fernández f6b1387659
ArrayTail: Fix support for optional parameters (#977)
Co-authored-by: som-sm <som-sm@users.noreply.github.com>
2024-12-02 13:21:01 +01:00

30 lines
673 B
TypeScript

import type {UnknownArrayOrTuple} from './internal';
/**
Extracts the type of an array or tuple minus the first element.
@example
```
import type {ArrayTail} from 'type-fest';
declare const curry: <Arguments extends unknown[], Return>(
function_: (...arguments_: Arguments) => Return,
...arguments_: ArrayTail<Arguments>
) => (...arguments_: ArrayTail<Arguments>) => Return;
const add = (a: number, b: number) => a + b;
const add3 = curry(add, 3);
add3(4);
//=> 7
```
@category Array
*/
export type ArrayTail<TArray extends UnknownArrayOrTuple> = TArray extends readonly [unknown?, ...infer Tail]
? keyof TArray & `${number}` extends never
? []
: Tail
: [];