-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathmappedArrayTupleIntersections.ts
More file actions
40 lines (28 loc) · 1.09 KB
/
mappedArrayTupleIntersections.ts
File metadata and controls
40 lines (28 loc) · 1.09 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
// @strict: true
// @noEmit: true
type Box<T> = { value: T };
type Boxify<T> = { [K in keyof T]: Box<T[K]> };
type T1 = Boxify<string[]>;
type T2 = Boxify<[string, string]>;
type T3 = Boxify<string[] & unknown[]>;
type T4 = Boxify<string[] & [string, string]>;
type T5 = Boxify<string[] & { x: string }>;
// https://github.com/microsoft/TypeScript/issues/57744
type MustBeArray<T extends any[]> = T;
type Hmm<T extends any[]> = T extends number[] ?
MustBeArray<{ [I in keyof T]: 1 }> :
never;
type X = Hmm<[3, 4, 5]>;
type MustHaveFooBar<T extends { foo: unknown; bar: unknown }> = T;
type Hmm2<T> = T extends { foo: string }[]
? T extends { bar: number }[]
? MustBeArray<{ [I in keyof T]: MustHaveFooBar<T[I]> }>
: never
: never;
type Y = Hmm2<[{ foo: string; bar: number }]>;
type MustHaveFoo<T extends { foo: unknown }> = T;
type Hmm3<T extends { foo: string }[]> = T extends { bar: string }
? MustBeArray<{ [I in keyof T]: MustHaveFoo<T[I]> }>
: never;
type Z1 = Hmm3<[{ foo: string }]>;
type Z2 = Hmm3<[{ foo: string }] & { bar: string }>;