mirror of
https://github.com/sindresorhus/type-fest.git
synced 2025-12-08 19:25:05 +00:00
Co-authored-by: Som Shekhar Mukherjee <49264891+som-sm@users.noreply.github.com> Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
30 lines
761 B
TypeScript
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 {};
|