forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexclude-rest-element.ts
More file actions
53 lines (43 loc) · 2.49 KB
/
exclude-rest-element.ts
File metadata and controls
53 lines (43 loc) · 2.49 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
41
42
43
44
45
46
47
48
49
50
51
52
53
import {expectType} from 'tsd';
import type {ExcludeRestElement} from '../index.d.ts';
// Basic Static Tuples (No Rest element)
expectType<ExcludeRestElement<[]>>({} as []);
expectType<ExcludeRestElement<[1]>>({} as [1]);
expectType<ExcludeRestElement<[1, 2, 3]>>({} as [1, 2, 3]);
expectType<ExcludeRestElement<readonly ['a', 'b']>>({} as readonly ['a', 'b']);
// Leading Rest element
expectType<ExcludeRestElement<[...string[], 1]>>({} as [1]);
expectType<ExcludeRestElement<[...number[], 'a', 'b']>>({} as ['a', 'b']);
expectType<ExcludeRestElement<[...any[], true]>>({} as [true]);
expectType<ExcludeRestElement<[...[], 'last']>>({} as ['last']);
expectType<ExcludeRestElement<[...never[], 'end']>>({} as ['end']);
expectType<ExcludeRestElement<[...unknown[], 2, 3]>>({} as [2, 3]);
// Middle Rest element
expectType<ExcludeRestElement<['a', ...string[], 'z']>>({} as ['a', 'z']);
expectType<ExcludeRestElement<['x', ...boolean[], true]>>({} as ['x', true]);
expectType<ExcludeRestElement<['x', ...any[], 'y']>>({} as ['x', 'y']);
expectType<ExcludeRestElement<['x', ...readonly number[], 'y']>>({} as ['x', 'y']);
// Trailing Rest element
expectType<ExcludeRestElement<[1, 2, ...string[]]>>({} as [1, 2]);
expectType<ExcludeRestElement<['foo', ...Array<'bar'>]>>({} as ['foo']);
expectType<ExcludeRestElement<[number, ...number[]]>>({} as [number]);
// Only Rest element
expectType<ExcludeRestElement<string[]>>({} as []);
expectType<ExcludeRestElement<readonly number[]>>({} as readonly []);
expectType<ExcludeRestElement<readonly [...boolean[]]>>({} as readonly []);
expectType<ExcludeRestElement<[...string[]]>>({} as []);
// Optional & Mixed Optional
expectType<ExcludeRestElement<[string?, boolean?, ...number[]]>>({} as [string?, boolean?]);
expectType<ExcludeRestElement<[1?, ...string[]]>>({} as [1?]);
// Unions
expectType<ExcludeRestElement<[1, ...string[]] | [2, ...number[]]>>({} as [1] | [2]);
expectType<ExcludeRestElement<[...boolean[], 'end'] | ['start', ...string[]]>>({} as ['end'] | ['start']);
// Readonly and Nested
expectType<ExcludeRestElement<readonly [...number[], 'done']>>({} as readonly ['done']);
expectType<ExcludeRestElement<readonly [1, ...string[], 2]>>({} as readonly [1, 2]);
// Arrays with Arrays Inside
expectType<ExcludeRestElement<[[1, 2], ...number[], [3, 4]]>>({} as [[1, 2], [3, 4]]);
expectType<ExcludeRestElement<[['a'], ...string[], ['z']]>>({} as [['a'], ['z']]);
// Edge: Never / Any
expectType<ExcludeRestElement<any>>({} as any);
expectType<ExcludeRestElement<never>>({} as never);