|
1 | 1 | //// [mappedTypeModifiers.ts] |
2 | 2 |
|
3 | 3 | type T = { a: number, b: string }; |
4 | | -type U = { a: number | undefined, b: string | undefined }; |
5 | | -type P = { a?: number, b?: string }; |
6 | | -type R = { readonly a: number, readonly b: string }; |
7 | | -type PR = { readonly a?: number, readonly b?: string }; |
| 4 | +type TU = { a: number | undefined, b: string | undefined }; |
| 5 | +type TP = { a?: number, b?: string }; |
| 6 | +type TR = { readonly a: number, readonly b: string }; |
| 7 | +type TPR = { readonly a?: number, readonly b?: string }; |
8 | 8 |
|
9 | 9 | // Validate they all have the same keys |
10 | 10 | var v00: "a" | "b"; |
11 | 11 | var v00: keyof T; |
12 | | -var v00: keyof U; |
13 | | -var v00: keyof P; |
14 | | -var v00: keyof R; |
15 | | -var v00: keyof PR; |
| 12 | +var v00: keyof TU; |
| 13 | +var v00: keyof TP; |
| 14 | +var v00: keyof TR; |
| 15 | +var v00: keyof TPR; |
16 | 16 |
|
17 | 17 | // Validate that non-isomorphic mapped types strip modifiers |
18 | 18 | var v01: T; |
19 | | -var v01: Pick<R, keyof T>; |
| 19 | +var v01: Pick<TR, keyof T>; |
20 | 20 | var v01: Pick<Readonly<T>, keyof T>; |
21 | 21 |
|
22 | 22 | // Validate that non-isomorphic mapped types strip modifiers |
23 | | -var v02: U; |
24 | | -var v02: Pick<P, keyof T>; |
25 | | -var v02: Pick<PR, keyof T>; |
| 23 | +var v02: TU; |
| 24 | +var v02: Pick<TP, keyof T>; |
| 25 | +var v02: Pick<TPR, keyof T>; |
26 | 26 | var v02: Pick<Partial<T>, keyof T>; |
27 | 27 | var v02: Pick<Partial<Readonly<T>>, keyof T>; |
28 | 28 |
|
29 | 29 | // Validate that isomorphic mapped types preserve optional modifier |
30 | | -var v03: P; |
| 30 | +var v03: TP; |
31 | 31 | var v03: Partial<T>; |
32 | 32 |
|
33 | 33 | // Validate that isomorphic mapped types preserve readonly modifier |
34 | | -var v04: R; |
| 34 | +var v04: TR; |
35 | 35 | var v04: Readonly<T>; |
36 | 36 |
|
37 | 37 | // Validate that isomorphic mapped types preserve both partial and readonly modifiers |
38 | | -var v05: PR; |
39 | | -var v05: Partial<R>; |
40 | | -var v05: Readonly<P>; |
| 38 | +var v05: TPR; |
| 39 | +var v05: Partial<TR>; |
| 40 | +var v05: Readonly<TP>; |
41 | 41 | var v05: Partial<Readonly<T>>; |
42 | | -var v05: Readonly<Partial<T>>; |
| 42 | +var v05: Readonly<Partial<T>>; |
| 43 | + |
| 44 | +type Boxified<T> = { [P in keyof T]: { x: T[P] } }; |
| 45 | + |
| 46 | +type B = { a: { x: number }, b: { x: string } }; |
| 47 | +type BU = { a: { x: number } | undefined, b: { x: string } | undefined }; |
| 48 | +type BP = { a?: { x: number }, b?: { x: string } }; |
| 49 | +type BR = { readonly a: { x: number }, readonly b: { x: string } }; |
| 50 | +type BPR = { readonly a?: { x: number }, readonly b?: { x: string } }; |
| 51 | + |
| 52 | +// Validate they all have the same keys |
| 53 | +var b00: "a" | "b"; |
| 54 | +var b00: keyof B; |
| 55 | +var b00: keyof BU; |
| 56 | +var b00: keyof BP; |
| 57 | +var b00: keyof BR; |
| 58 | +var b00: keyof BPR; |
| 59 | + |
| 60 | +// Validate that non-isomorphic mapped types strip modifiers |
| 61 | +var b01: B; |
| 62 | +var b01: Pick<BR, keyof B>; |
| 63 | +var b01: Pick<Readonly<BR>, keyof B>; |
| 64 | + |
| 65 | +// Validate that non-isomorphic mapped types strip modifiers |
| 66 | +var b02: BU; |
| 67 | +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 | + |
| 76 | +// Validate that isomorphic mapped types preserve readonly modifier |
| 77 | +var b04: BR; |
| 78 | +var b04: Readonly<B>; |
| 79 | + |
| 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>>; |
43 | 86 |
|
44 | 87 | //// [mappedTypeModifiers.js] |
45 | 88 | // Validate they all have the same keys |
@@ -71,3 +114,32 @@ var v05; |
71 | 114 | var v05; |
72 | 115 | var v05; |
73 | 116 | var v05; |
| 117 | +// Validate they all have the same keys |
| 118 | +var b00; |
| 119 | +var b00; |
| 120 | +var b00; |
| 121 | +var b00; |
| 122 | +var b00; |
| 123 | +var b00; |
| 124 | +// Validate that non-isomorphic mapped types strip modifiers |
| 125 | +var b01; |
| 126 | +var b01; |
| 127 | +var b01; |
| 128 | +// Validate that non-isomorphic mapped types strip modifiers |
| 129 | +var b02; |
| 130 | +var b02; |
| 131 | +var b02; |
| 132 | +var b02; |
| 133 | +var b02; |
| 134 | +// Validate that isomorphic mapped types preserve optional modifier |
| 135 | +var b03; |
| 136 | +var b03; |
| 137 | +// Validate that isomorphic mapped types preserve readonly modifier |
| 138 | +var b04; |
| 139 | +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