-
-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathexclude-rest-element.d.ts
More file actions
40 lines (32 loc) · 1.14 KB
/
exclude-rest-element.d.ts
File metadata and controls
40 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import type {SplitOnRestElement} from './split-on-rest-element.d.ts';
import type {IsArrayReadonly} from './internal/array.d.ts';
import type {UnknownArray} from './unknown-array.d.ts';
import type {IfNotAnyOrNever} from './internal/type.d.ts';
/**
Create a tuple with the [`rest`](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) element removed.
@example
```
import type {ExcludeRestElement} from 'type-fest';
type T1 = ExcludeRestElement<[number, ...string[], string, 'foo']>;
//=> [number, string, 'foo']
type T2 = ExcludeRestElement<[...boolean[], string]>;
//=> [string]
type T3 = ExcludeRestElement<[...Array<'foo'>, true]>;
//=> [true]
type T4 = ExcludeRestElement<[number, string]>;
//=> [number, string]
```
@see {@link ExtractRestElement}
@see {@link SplitOnRestElement}
@category Array
*/
export type ExcludeRestElement<Array_ extends UnknownArray> = IfNotAnyOrNever<Array_,
SplitOnRestElement<Array_> extends infer Result
? Result extends readonly UnknownArray[]
? IsArrayReadonly<Array_> extends true
? Readonly<[...Result[0], ...Result[2]]>
: [...Result[0], ...Result[2]]
: never
: never
>;
export {};