• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// @strict: true
2// @declaration: true
3
4type T00 = [string?];
5type T01 = [string, string?];
6type T02 = [string?, string];  // Error
7type T03 = [...string[]];
8type T04 = [...[...string[]]];
9type T05 = [...[...[...string[]]]];
10type T06 = [string, ...string[]];
11type T07 = [...string[], string];  // Error
12type T08 = [...string];  // Error
13type T09 = [...string?];  // Error
14type T10 = [string, ...[...string[]]];
15type T11 = [string, ...[...[...string[]]]];
16
17type T15 = [boolean, number, ...string[]];
18type L15 = T15["length"];  // number
19
20declare function assign<T, S extends T>(): void;
21
22assign<number[], [...number[]]>();
23assign<number[], [number, ...number[]]>();
24assign<[...number[]], number[]>();
25
26assign<[number, ...number[]], number[]>();  // Error
27assign<[number, ...number[]], []>();  // Error
28assign<[number, ...number[]], [number]>();
29assign<[number, ...number[]], [number, number]>();
30assign<[number, ...number[]], [number, number, ...number[]]>();
31
32assign<[number], [...number[]]>();  // Error
33assign<[number], [number, ...number[]]>();  // Error
34
35assign<[number, ...number[]], [number, ...string[]]>();  // Error
36assign<[number, ...number[]], [string, ...number[]]>();  // Error
37assign<[number, ...number[]], [number, number, string]>();  // Error
38assign<[number, ...number[]], [number, number, number, string]>();  // Error
39
40type T20 = [number, string, ...boolean[]];
41
42type T21 = T20[0];
43type T22 = T20[0 | 1];
44type T23 = T20[0 | 1 | 2];
45type T24 = T20[0 | 1 | 2 | 3];
46type T25 = T20[1 | 2 | 3];
47type T26 = T20[2 | 3];
48type T27 = T20[3];
49type T28 = T20[number];
50
51declare const t: T20;
52declare const x: number;
53
54let e0 = t[0];  // number
55let e1 = t[1];  // string
56let e2 = t[2];  // boolean
57let e3 = t[3];  // boolean
58let ex = t[x];  // number | string | boolean
59
60declare function f0<T, U>(x: [T, ...U[]]): [T, U];
61
62f0([]);  // Error
63f0([1]);
64f0([1, 2, 3]);
65f0([1, "hello", true]);
66
67declare function f1(a: [(x: number) => number, ...((x: string) => number)[]]): void;
68declare function f2(...a: [(x: number) => number, ...((x: string) => number)[]]): void;
69
70f1([x => x * 2, x => x.length, x => x.charCodeAt(0)]);
71f2(x => x * 2, x => x.length, x => x.charCodeAt(0));
72