type-fest/source/extract-rest-element.d.ts
benz 34b8fadfa3
Add SplitOnRestElement, ExtractRestElement, ExcludeRestElement types (#1166)
Co-authored-by: Som Shekhar Mukherjee <49264891+som-sm@users.noreply.github.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
2025-10-11 13:43:16 +09:00

30 lines
761 B
TypeScript

import type {SplitOnRestElement} from './split-on-rest-element.d.ts';
import type {UnknownArray} from './unknown-array.d.ts';
/**
Extracts the [`rest`](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) element type from an array.
@example
```
import type {ExtractRestElement} from 'type-fest';
type T1 = ExtractRestElement<[number, ...string[], string, 'foo']>;
//=> string
type T2 = ExtractRestElement<[...boolean[], string]>;
//=> boolean
type T3 = ExtractRestElement<[...'foo'[], true]>;
//=> 'foo'
type T4 = ExtractRestElement<[number, string]>;
//=> never
```
@see ExcludeRestElement, SplitOnRestElement
@category Array
*/
export type ExtractRestElement<T extends UnknownArray> = SplitOnRestElement<T>[1][number];
export {};