Skip to content

Commit e9b6ddc

Browse files
committed
Add tests
1 parent 364142c commit e9b6ddc

File tree

12 files changed

+1822
-0
lines changed

12 files changed

+1822
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
//// [mappedTypes1.ts]
2+
3+
type Item = { a: string, b: number, c: boolean };
4+
5+
type T00 = { [P in "x" | "y"]: number };
6+
type T01 = { [P in "x" | "y"]: P };
7+
type T02 = { [P in "a" | "b"]: Item[P]; }
8+
type T03 = { [P in keyof Item]: Date };
9+
10+
type T10 = { [P in keyof Item]: Item[P] };
11+
type T11 = { [P in keyof Item]?: Item[P] };
12+
type T12 = { readonly [P in keyof Item]: Item[P] };
13+
type T13 = { readonly [P in keyof Item]?: Item[P] };
14+
15+
type T20 = { [P in keyof Item]: Item[P] | null };
16+
type T21 = { [P in keyof Item]: Array<Item[P]> };
17+
18+
type T30 = { [P in keyof any]: void };
19+
type T31 = { [P in keyof string]: void };
20+
type T32 = { [P in keyof number]: void };
21+
type T33 = { [P in keyof boolean]: void };
22+
type T34 = { [P in keyof undefined]: void };
23+
type T35 = { [P in keyof null]: void };
24+
type T36 = { [P in keyof void]: void };
25+
type T37 = { [P in keyof symbol]: void };
26+
type T38 = { [P in keyof never]: void };
27+
28+
declare function f1<T1>(): { [P in keyof T1]: void };
29+
declare function f2<T1 extends string>(): { [P in keyof T1]: void };
30+
declare function f3<T1 extends number>(): { [P in keyof T1]: void };
31+
32+
let x1 = f1();
33+
let x2 = f2();
34+
let x3 = f3();
35+
36+
//// [mappedTypes1.js]
37+
var x1 = f1();
38+
var x2 = f2();
39+
var x3 = f3();
40+
41+
42+
//// [mappedTypes1.d.ts]
43+
declare type Item = {
44+
a: string;
45+
b: number;
46+
c: boolean;
47+
};
48+
declare type T00 = {
49+
[P in "x" | "y"]: number;
50+
};
51+
declare type T01 = {
52+
[P in "x" | "y"]: P;
53+
};
54+
declare type T02 = {
55+
[P in "a" | "b"]: Item[P];
56+
};
57+
declare type T03 = {
58+
[P in keyof Item]: Date;
59+
};
60+
declare type T10 = {
61+
[P in keyof Item]: Item[P];
62+
};
63+
declare type T11 = {
64+
[P in keyof Item]?: Item[P];
65+
};
66+
declare type T12 = {
67+
readonly [P in keyof Item]: Item[P];
68+
};
69+
declare type T13 = {
70+
readonly [P in keyof Item]?: Item[P];
71+
};
72+
declare type T20 = {
73+
[P in keyof Item]: Item[P] | null;
74+
};
75+
declare type T21 = {
76+
[P in keyof Item]: Array<Item[P]>;
77+
};
78+
declare type T30 = {
79+
[P in keyof any]: void;
80+
};
81+
declare type T31 = {
82+
[P in keyof string]: void;
83+
};
84+
declare type T32 = {
85+
[P in keyof number]: void;
86+
};
87+
declare type T33 = {
88+
[P in keyof boolean]: void;
89+
};
90+
declare type T34 = {
91+
[P in keyof undefined]: void;
92+
};
93+
declare type T35 = {
94+
[P in keyof null]: void;
95+
};
96+
declare type T36 = {
97+
[P in keyof void]: void;
98+
};
99+
declare type T37 = {
100+
[P in keyof symbol]: void;
101+
};
102+
declare type T38 = {
103+
[P in keyof never]: void;
104+
};
105+
declare function f1<T1>(): {
106+
[P in keyof T1]: void;
107+
};
108+
declare function f2<T1 extends string>(): {
109+
[P in keyof T1]: void;
110+
};
111+
declare function f3<T1 extends number>(): {
112+
[P in keyof T1]: void;
113+
};
114+
declare let x1: {};
115+
declare let x2: {
116+
[x: number]: void;
117+
toString: void;
118+
charAt: void;
119+
charCodeAt: void;
120+
concat: void;
121+
indexOf: void;
122+
lastIndexOf: void;
123+
localeCompare: void;
124+
match: void;
125+
replace: void;
126+
search: void;
127+
slice: void;
128+
split: void;
129+
substring: void;
130+
toLowerCase: void;
131+
toLocaleLowerCase: void;
132+
toUpperCase: void;
133+
toLocaleUpperCase: void;
134+
trim: void;
135+
length: void;
136+
substr: void;
137+
valueOf: void;
138+
};
139+
declare let x3: {
140+
toString: void;
141+
valueOf: void;
142+
toFixed: void;
143+
toExponential: void;
144+
toPrecision: void;
145+
toLocaleString: void;
146+
};
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
=== tests/cases/conformance/types/mapped/mappedTypes1.ts ===
2+
3+
type Item = { a: string, b: number, c: boolean };
4+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
5+
>a : Symbol(a, Decl(mappedTypes1.ts, 1, 13))
6+
>b : Symbol(b, Decl(mappedTypes1.ts, 1, 24))
7+
>c : Symbol(c, Decl(mappedTypes1.ts, 1, 35))
8+
9+
type T00 = { [P in "x" | "y"]: number };
10+
>T00 : Symbol(T00, Decl(mappedTypes1.ts, 1, 49))
11+
>P : Symbol(P, Decl(mappedTypes1.ts, 3, 14))
12+
13+
type T01 = { [P in "x" | "y"]: P };
14+
>T01 : Symbol(T01, Decl(mappedTypes1.ts, 3, 40))
15+
>P : Symbol(P, Decl(mappedTypes1.ts, 4, 14))
16+
>P : Symbol(P, Decl(mappedTypes1.ts, 4, 14))
17+
18+
type T02 = { [P in "a" | "b"]: Item[P]; }
19+
>T02 : Symbol(T02, Decl(mappedTypes1.ts, 4, 35))
20+
>P : Symbol(P, Decl(mappedTypes1.ts, 5, 14))
21+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
22+
>P : Symbol(P, Decl(mappedTypes1.ts, 5, 14))
23+
24+
type T03 = { [P in keyof Item]: Date };
25+
>T03 : Symbol(T03, Decl(mappedTypes1.ts, 5, 41))
26+
>P : Symbol(P, Decl(mappedTypes1.ts, 6, 14))
27+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
28+
>Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
29+
30+
type T10 = { [P in keyof Item]: Item[P] };
31+
>T10 : Symbol(T10, Decl(mappedTypes1.ts, 6, 39))
32+
>P : Symbol(P, Decl(mappedTypes1.ts, 8, 14))
33+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
34+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
35+
>P : Symbol(P, Decl(mappedTypes1.ts, 8, 14))
36+
37+
type T11 = { [P in keyof Item]?: Item[P] };
38+
>T11 : Symbol(T11, Decl(mappedTypes1.ts, 8, 42))
39+
>P : Symbol(P, Decl(mappedTypes1.ts, 9, 14))
40+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
41+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
42+
>P : Symbol(P, Decl(mappedTypes1.ts, 9, 14))
43+
44+
type T12 = { readonly [P in keyof Item]: Item[P] };
45+
>T12 : Symbol(T12, Decl(mappedTypes1.ts, 9, 43))
46+
>P : Symbol(P, Decl(mappedTypes1.ts, 10, 23))
47+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
48+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
49+
>P : Symbol(P, Decl(mappedTypes1.ts, 10, 23))
50+
51+
type T13 = { readonly [P in keyof Item]?: Item[P] };
52+
>T13 : Symbol(T13, Decl(mappedTypes1.ts, 10, 51))
53+
>P : Symbol(P, Decl(mappedTypes1.ts, 11, 23))
54+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
55+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
56+
>P : Symbol(P, Decl(mappedTypes1.ts, 11, 23))
57+
58+
type T20 = { [P in keyof Item]: Item[P] | null };
59+
>T20 : Symbol(T20, Decl(mappedTypes1.ts, 11, 52))
60+
>P : Symbol(P, Decl(mappedTypes1.ts, 13, 14))
61+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
62+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
63+
>P : Symbol(P, Decl(mappedTypes1.ts, 13, 14))
64+
65+
type T21 = { [P in keyof Item]: Array<Item[P]> };
66+
>T21 : Symbol(T21, Decl(mappedTypes1.ts, 13, 49))
67+
>P : Symbol(P, Decl(mappedTypes1.ts, 14, 14))
68+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
69+
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
70+
>Item : Symbol(Item, Decl(mappedTypes1.ts, 0, 0))
71+
>P : Symbol(P, Decl(mappedTypes1.ts, 14, 14))
72+
73+
type T30 = { [P in keyof any]: void };
74+
>T30 : Symbol(T30, Decl(mappedTypes1.ts, 14, 49))
75+
>P : Symbol(P, Decl(mappedTypes1.ts, 16, 14))
76+
77+
type T31 = { [P in keyof string]: void };
78+
>T31 : Symbol(T31, Decl(mappedTypes1.ts, 16, 38))
79+
>P : Symbol(P, Decl(mappedTypes1.ts, 17, 14))
80+
81+
type T32 = { [P in keyof number]: void };
82+
>T32 : Symbol(T32, Decl(mappedTypes1.ts, 17, 41))
83+
>P : Symbol(P, Decl(mappedTypes1.ts, 18, 14))
84+
85+
type T33 = { [P in keyof boolean]: void };
86+
>T33 : Symbol(T33, Decl(mappedTypes1.ts, 18, 41))
87+
>P : Symbol(P, Decl(mappedTypes1.ts, 19, 14))
88+
89+
type T34 = { [P in keyof undefined]: void };
90+
>T34 : Symbol(T34, Decl(mappedTypes1.ts, 19, 42))
91+
>P : Symbol(P, Decl(mappedTypes1.ts, 20, 14))
92+
93+
type T35 = { [P in keyof null]: void };
94+
>T35 : Symbol(T35, Decl(mappedTypes1.ts, 20, 44))
95+
>P : Symbol(P, Decl(mappedTypes1.ts, 21, 14))
96+
97+
type T36 = { [P in keyof void]: void };
98+
>T36 : Symbol(T36, Decl(mappedTypes1.ts, 21, 39))
99+
>P : Symbol(P, Decl(mappedTypes1.ts, 22, 14))
100+
101+
type T37 = { [P in keyof symbol]: void };
102+
>T37 : Symbol(T37, Decl(mappedTypes1.ts, 22, 39))
103+
>P : Symbol(P, Decl(mappedTypes1.ts, 23, 14))
104+
105+
type T38 = { [P in keyof never]: void };
106+
>T38 : Symbol(T38, Decl(mappedTypes1.ts, 23, 41))
107+
>P : Symbol(P, Decl(mappedTypes1.ts, 24, 14))
108+
109+
declare function f1<T1>(): { [P in keyof T1]: void };
110+
>f1 : Symbol(f1, Decl(mappedTypes1.ts, 24, 40))
111+
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 26, 20))
112+
>P : Symbol(P, Decl(mappedTypes1.ts, 26, 30))
113+
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 26, 20))
114+
115+
declare function f2<T1 extends string>(): { [P in keyof T1]: void };
116+
>f2 : Symbol(f2, Decl(mappedTypes1.ts, 26, 53))
117+
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 27, 20))
118+
>P : Symbol(P, Decl(mappedTypes1.ts, 27, 45))
119+
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 27, 20))
120+
121+
declare function f3<T1 extends number>(): { [P in keyof T1]: void };
122+
>f3 : Symbol(f3, Decl(mappedTypes1.ts, 27, 68))
123+
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 28, 20))
124+
>P : Symbol(P, Decl(mappedTypes1.ts, 28, 45))
125+
>T1 : Symbol(T1, Decl(mappedTypes1.ts, 28, 20))
126+
127+
let x1 = f1();
128+
>x1 : Symbol(x1, Decl(mappedTypes1.ts, 30, 3))
129+
>f1 : Symbol(f1, Decl(mappedTypes1.ts, 24, 40))
130+
131+
let x2 = f2();
132+
>x2 : Symbol(x2, Decl(mappedTypes1.ts, 31, 3))
133+
>f2 : Symbol(f2, Decl(mappedTypes1.ts, 26, 53))
134+
135+
let x3 = f3();
136+
>x3 : Symbol(x3, Decl(mappedTypes1.ts, 32, 3))
137+
>f3 : Symbol(f3, Decl(mappedTypes1.ts, 27, 68))
138+

0 commit comments

Comments
 (0)