|
1 | 1 | //// [mappedTypeModifiers.ts] |
2 | 2 |
|
3 | 3 | type T = { a: number, b: string }; |
4 | | -type TU = { a: number | undefined, b: string | undefined }; |
5 | 4 | type TP = { a?: number, b?: string }; |
6 | 5 | type TR = { readonly a: number, readonly b: string }; |
7 | 6 | type TPR = { readonly a?: number, readonly b?: string }; |
8 | 7 |
|
9 | | -// Validate they all have the same keys |
10 | 8 | var v00: "a" | "b"; |
11 | 9 | var v00: keyof T; |
12 | | -var v00: keyof TU; |
13 | 10 | var v00: keyof TP; |
14 | 11 | var v00: keyof TR; |
15 | 12 | var v00: keyof TPR; |
16 | 13 |
|
17 | | -// Validate that non-isomorphic mapped types strip modifiers |
18 | 14 | var v01: T; |
19 | | -var v01: Pick<TR, keyof T>; |
20 | | -var v01: Pick<Readonly<T>, keyof T>; |
| 15 | +var v01: { [P in keyof T]: T[P] }; |
| 16 | +var v01: Pick<T, keyof T>; |
| 17 | +var v01: Pick<Pick<T, keyof T>, keyof T>; |
21 | 18 |
|
22 | | -// Validate that non-isomorphic mapped types strip modifiers |
23 | | -var v02: TU; |
| 19 | +var v02: TP; |
| 20 | +var v02: { [P in keyof T]?: T[P] }; |
| 21 | +var v02: Partial<T>; |
24 | 22 | var v02: Pick<TP, keyof T>; |
25 | | -var v02: Pick<TPR, keyof T>; |
26 | | -var v02: Pick<Partial<T>, keyof T>; |
27 | | -var v02: Pick<Partial<Readonly<T>>, keyof T>; |
28 | 23 |
|
29 | | -// Validate that isomorphic mapped types preserve optional modifier |
30 | | -var v03: TP; |
31 | | -var v03: Partial<T>; |
| 24 | +var v03: TR; |
| 25 | +var v03: { readonly [P in keyof T]: T[P] }; |
| 26 | +var v03: Readonly<T>; |
| 27 | +var v03: Pick<TR, keyof T>; |
32 | 28 |
|
33 | | -// Validate that isomorphic mapped types preserve readonly modifier |
34 | | -var v04: TR; |
35 | | -var v04: Readonly<T>; |
36 | | - |
37 | | -// Validate that isomorphic mapped types preserve both partial and readonly modifiers |
38 | | -var v05: TPR; |
39 | | -var v05: Partial<TR>; |
40 | | -var v05: Readonly<TP>; |
41 | | -var v05: Partial<Readonly<T>>; |
42 | | -var v05: Readonly<Partial<T>>; |
| 29 | +var v04: TPR; |
| 30 | +var v04: { readonly [P in keyof T]?: T[P] }; |
| 31 | +var v04: Partial<TR>; |
| 32 | +var v04: Readonly<TP>; |
| 33 | +var v04: Partial<Readonly<T>>; |
| 34 | +var v04: Readonly<Partial<T>>; |
| 35 | +var v04: Pick<TPR, keyof T>; |
43 | 36 |
|
44 | 37 | type Boxified<T> = { [P in keyof T]: { x: T[P] } }; |
45 | 38 |
|
46 | 39 | type B = { a: { x: number }, b: { x: string } }; |
47 | | -type BU = { a: { x: number } | undefined, b: { x: string } | undefined }; |
48 | 40 | type BP = { a?: { x: number }, b?: { x: string } }; |
49 | 41 | type BR = { readonly a: { x: number }, readonly b: { x: string } }; |
50 | 42 | type BPR = { readonly a?: { x: number }, readonly b?: { x: string } }; |
51 | 43 |
|
52 | | -// Validate they all have the same keys |
53 | 44 | var b00: "a" | "b"; |
54 | 45 | var b00: keyof B; |
55 | | -var b00: keyof BU; |
56 | 46 | var b00: keyof BP; |
57 | 47 | var b00: keyof BR; |
58 | 48 | var b00: keyof BPR; |
59 | 49 |
|
60 | | -// Validate that non-isomorphic mapped types strip modifiers |
61 | 50 | var b01: B; |
62 | | -var b01: Pick<BR, keyof B>; |
63 | | -var b01: Pick<Readonly<BR>, keyof B>; |
| 51 | +var b01: { [P in keyof B]: B[P] }; |
| 52 | +var b01: Pick<B, keyof B>; |
| 53 | +var b01: Pick<Pick<B, keyof B>, keyof B>; |
64 | 54 |
|
65 | | -// Validate that non-isomorphic mapped types strip modifiers |
66 | | -var b02: BU; |
| 55 | +var b02: BP; |
| 56 | +var b02: { [P in keyof B]?: B[P] }; |
| 57 | +var b02: Partial<B>; |
67 | 58 | var b02: Pick<BP, keyof B>; |
68 | | -var b02: Pick<BPR, keyof B>; |
69 | | -var b02: Pick<Partial<B>, keyof B>; |
70 | | -var b02: Pick<Partial<Readonly<B>>, keyof B>; |
71 | | - |
72 | | -// Validate that isomorphic mapped types preserve optional modifier |
73 | | -var b03: BP; |
74 | | -var b03: Partial<B>; |
75 | 59 |
|
76 | | -// Validate that isomorphic mapped types preserve readonly modifier |
77 | | -var b04: BR; |
78 | | -var b04: Readonly<B>; |
| 60 | +var b03: BR; |
| 61 | +var b03: { readonly [P in keyof B]: B[P] }; |
| 62 | +var b03: Readonly<B>; |
| 63 | +var b03: Pick<BR, keyof B>; |
79 | 64 |
|
80 | | -// Validate that isomorphic mapped types preserve both partial and readonly modifiers |
81 | | -var b05: BPR; |
82 | | -var b05: Partial<BR>; |
83 | | -var b05: Readonly<BP>; |
84 | | -var b05: Partial<Readonly<B>>; |
85 | | -var b05: Readonly<Partial<B>>; |
| 65 | +var b04: BPR; |
| 66 | +var b04: { readonly [P in keyof B]?: B[P] }; |
| 67 | +var b04: Partial<BR>; |
| 68 | +var b04: Readonly<BP>; |
| 69 | +var b04: Partial<Readonly<B>>; |
| 70 | +var b04: Readonly<Partial<B>>; |
| 71 | +var b04: Pick<BPR, keyof B>; |
86 | 72 |
|
87 | 73 | //// [mappedTypeModifiers.js] |
88 | | -// Validate they all have the same keys |
89 | | -var v00; |
90 | 74 | var v00; |
91 | 75 | var v00; |
92 | 76 | var v00; |
93 | 77 | var v00; |
94 | 78 | var v00; |
95 | | -// Validate that non-isomorphic mapped types strip modifiers |
96 | 79 | var v01; |
97 | 80 | var v01; |
98 | 81 | var v01; |
99 | | -// Validate that non-isomorphic mapped types strip modifiers |
100 | | -var v02; |
| 82 | +var v01; |
101 | 83 | var v02; |
102 | 84 | var v02; |
103 | 85 | var v02; |
104 | 86 | var v02; |
105 | | -// Validate that isomorphic mapped types preserve optional modifier |
106 | 87 | var v03; |
107 | 88 | var v03; |
108 | | -// Validate that isomorphic mapped types preserve readonly modifier |
| 89 | +var v03; |
| 90 | +var v03; |
| 91 | +var v04; |
| 92 | +var v04; |
| 93 | +var v04; |
| 94 | +var v04; |
| 95 | +var v04; |
109 | 96 | var v04; |
110 | 97 | var v04; |
111 | | -// Validate that isomorphic mapped types preserve both partial and readonly modifiers |
112 | | -var v05; |
113 | | -var v05; |
114 | | -var v05; |
115 | | -var v05; |
116 | | -var v05; |
117 | | -// Validate they all have the same keys |
118 | | -var b00; |
119 | 98 | var b00; |
120 | 99 | var b00; |
121 | 100 | var b00; |
122 | 101 | var b00; |
123 | 102 | var b00; |
124 | | -// Validate that non-isomorphic mapped types strip modifiers |
125 | 103 | var b01; |
126 | 104 | var b01; |
127 | 105 | var b01; |
128 | | -// Validate that non-isomorphic mapped types strip modifiers |
129 | | -var b02; |
| 106 | +var b01; |
130 | 107 | var b02; |
131 | 108 | var b02; |
132 | 109 | var b02; |
133 | 110 | var b02; |
134 | | -// Validate that isomorphic mapped types preserve optional modifier |
135 | 111 | var b03; |
136 | 112 | var b03; |
137 | | -// Validate that isomorphic mapped types preserve readonly modifier |
| 113 | +var b03; |
| 114 | +var b03; |
| 115 | +var b04; |
| 116 | +var b04; |
| 117 | +var b04; |
| 118 | +var b04; |
| 119 | +var b04; |
138 | 120 | var b04; |
139 | 121 | var b04; |
140 | | -// Validate that isomorphic mapped types preserve both partial and readonly modifiers |
141 | | -var b05; |
142 | | -var b05; |
143 | | -var b05; |
144 | | -var b05; |
145 | | -var b05; |
0 commit comments