-
Notifications
You must be signed in to change notification settings - Fork 12.8k
/
Copy pathmappedTypeModifiers.js
145 lines (129 loc) · 3.68 KB
/
mappedTypeModifiers.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//// [mappedTypeModifiers.ts]
type T = { a: number, b: string };
type TU = { a: number | undefined, b: string | undefined };
type TP = { a?: number, b?: string };
type TR = { readonly a: number, readonly b: string };
type TPR = { readonly a?: number, readonly b?: string };
// Validate they all have the same keys
var v00: "a" | "b";
var v00: keyof T;
var v00: keyof TU;
var v00: keyof TP;
var v00: keyof TR;
var v00: keyof TPR;
// Validate that non-isomorphic mapped types strip modifiers
var v01: T;
var v01: Pick<TR, keyof T>;
var v01: Pick<Readonly<T>, keyof T>;
// Validate that non-isomorphic mapped types strip modifiers
var v02: TU;
var v02: Pick<TP, keyof T>;
var v02: Pick<TPR, keyof T>;
var v02: Pick<Partial<T>, keyof T>;
var v02: Pick<Partial<Readonly<T>>, keyof T>;
// Validate that isomorphic mapped types preserve optional modifier
var v03: TP;
var v03: Partial<T>;
// Validate that isomorphic mapped types preserve readonly modifier
var v04: TR;
var v04: Readonly<T>;
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var v05: TPR;
var v05: Partial<TR>;
var v05: Readonly<TP>;
var v05: Partial<Readonly<T>>;
var v05: Readonly<Partial<T>>;
type Boxified<T> = { [P in keyof T]: { x: T[P] } };
type B = { a: { x: number }, b: { x: string } };
type BU = { a: { x: number } | undefined, b: { x: string } | undefined };
type BP = { a?: { x: number }, b?: { x: string } };
type BR = { readonly a: { x: number }, readonly b: { x: string } };
type BPR = { readonly a?: { x: number }, readonly b?: { x: string } };
// Validate they all have the same keys
var b00: "a" | "b";
var b00: keyof B;
var b00: keyof BU;
var b00: keyof BP;
var b00: keyof BR;
var b00: keyof BPR;
// Validate that non-isomorphic mapped types strip modifiers
var b01: B;
var b01: Pick<BR, keyof B>;
var b01: Pick<Readonly<BR>, keyof B>;
// Validate that non-isomorphic mapped types strip modifiers
var b02: BU;
var b02: Pick<BP, keyof B>;
var b02: Pick<BPR, keyof B>;
var b02: Pick<Partial<B>, keyof B>;
var b02: Pick<Partial<Readonly<B>>, keyof B>;
// Validate that isomorphic mapped types preserve optional modifier
var b03: BP;
var b03: Partial<B>;
// Validate that isomorphic mapped types preserve readonly modifier
var b04: BR;
var b04: Readonly<B>;
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var b05: BPR;
var b05: Partial<BR>;
var b05: Readonly<BP>;
var b05: Partial<Readonly<B>>;
var b05: Readonly<Partial<B>>;
//// [mappedTypeModifiers.js]
// Validate they all have the same keys
var v00;
var v00;
var v00;
var v00;
var v00;
var v00;
// Validate that non-isomorphic mapped types strip modifiers
var v01;
var v01;
var v01;
// Validate that non-isomorphic mapped types strip modifiers
var v02;
var v02;
var v02;
var v02;
var v02;
// Validate that isomorphic mapped types preserve optional modifier
var v03;
var v03;
// Validate that isomorphic mapped types preserve readonly modifier
var v04;
var v04;
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var v05;
var v05;
var v05;
var v05;
var v05;
// Validate they all have the same keys
var b00;
var b00;
var b00;
var b00;
var b00;
var b00;
// Validate that non-isomorphic mapped types strip modifiers
var b01;
var b01;
var b01;
// Validate that non-isomorphic mapped types strip modifiers
var b02;
var b02;
var b02;
var b02;
var b02;
// Validate that isomorphic mapped types preserve optional modifier
var b03;
var b03;
// Validate that isomorphic mapped types preserve readonly modifier
var b04;
var b04;
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
var b05;
var b05;
var b05;
var b05;
var b05;