Skip to content

Commit 65e98c8

Browse files
committed
Add more tests
1 parent f366ae0 commit 65e98c8

File tree

4 files changed

+574
-129
lines changed

4 files changed

+574
-129
lines changed

Diff for: tests/baselines/reference/mappedTypeModifiers.js

+90-18
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,88 @@
11
//// [mappedTypeModifiers.ts]
22

33
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 };
88

99
// Validate they all have the same keys
1010
var v00: "a" | "b";
1111
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;
1616

1717
// Validate that non-isomorphic mapped types strip modifiers
1818
var v01: T;
19-
var v01: Pick<R, keyof T>;
19+
var v01: Pick<TR, keyof T>;
2020
var v01: Pick<Readonly<T>, keyof T>;
2121

2222
// 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>;
2626
var v02: Pick<Partial<T>, keyof T>;
2727
var v02: Pick<Partial<Readonly<T>>, keyof T>;
2828

2929
// Validate that isomorphic mapped types preserve optional modifier
30-
var v03: P;
30+
var v03: TP;
3131
var v03: Partial<T>;
3232

3333
// Validate that isomorphic mapped types preserve readonly modifier
34-
var v04: R;
34+
var v04: TR;
3535
var v04: Readonly<T>;
3636

3737
// 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>;
4141
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>>;
4386

4487
//// [mappedTypeModifiers.js]
4588
// Validate they all have the same keys
@@ -71,3 +114,32 @@ var v05;
71114
var v05;
72115
var v05;
73116
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

Comments
 (0)