File tree Expand file tree Collapse file tree
tests/cases/conformance/types/mapped Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // @strictNullChecks : true
2+ // @declaration : true
3+
4+ type Partial < T > = {
5+ [ P in keyof T ] ?: T [ P ] ;
6+ } ;
7+
8+ type Readonly < T > = {
9+ readonly [ P in keyof T ] : T [ P ] ;
10+ } ;
11+
12+ type Pick < T , K extends keyof T > = {
13+ [ P in K ] : T [ P ] ;
14+ }
15+
16+ type Record < K extends string | number , T > = {
17+ [ _ in K ] : T ;
18+ }
19+
20+ interface Shape {
21+ name : string ;
22+ width : number ;
23+ height : number ;
24+ visible : boolean ;
25+ }
26+
27+ interface Named {
28+ name : string ;
29+ }
30+
31+ interface Point {
32+ x : number ;
33+ y : number ;
34+ }
35+
36+ type T00 = { [ P in P ] : string } ; // Error
37+ type T01 = { [ P in Date ] : number } ; // Error
38+ type T02 = Record < Date , number > ; // Error
39+
40+ type T10 = Pick < Shape , "name" > ;
41+ type T11 = Pick < Shape , "foo" > ; // Error
42+ type T12 = Pick < Shape , "name" | "foo" > ; // Error
43+ type T13 = Pick < Shape , keyof Named > ;
44+ type T14 = Pick < Shape , keyof Point > ; // Error
45+ type T15 = Pick < Shape , never > ;
46+ type T16 = Pick < Shape , undefined > ;
47+
48+ function f1 < T > ( x : T ) {
49+ let y : Pick < Shape , T > ; // Error
50+ }
51+
52+ function f2 < T extends string | number > ( x : T ) {
53+ let y : Pick < Shape , T > ; // Error
54+ }
55+
56+ function f3 < T extends keyof Shape > ( x : T ) {
57+ let y : Pick < Shape , T > ;
58+ }
59+
60+ function f4 < T extends keyof Named > ( x : T ) {
61+ let y : Pick < Shape , T > ;
62+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,15 @@ type T36 = { [P in keyof void]: void };
2626type T37 = { [ P in keyof symbol ] : void } ;
2727type T38 = { [ P in keyof never ] : void } ;
2828
29+ type T40 = { [ P in string ] : void } ;
30+ type T41 = { [ P in number ] : void } ;
31+ type T42 = { [ P in string | number ] : void } ;
32+ type T43 = { [ P in "a" | "b" | 0 | 1 ] : void } ;
33+ type T44 = { [ P in "a" | "b" | "0" | "1" ] : void } ;
34+ type T45 = { [ P in "a" | "b" | "0" | "1" | 0 | 1 ] : void } ;
35+ type T46 = { [ P in number | "a" | "b" | 0 | 1 ] : void } ;
36+ type T47 = { [ P in string | number | "a" | "b" | 0 | 1 ] : void } ;
37+
2938declare function f1 < T1 > ( ) : { [ P in keyof T1 ] : void } ;
3039declare function f2 < T1 extends string > ( ) : { [ P in keyof T1 ] : void } ;
3140declare function f3 < T1 extends number > ( ) : { [ P in keyof T1 ] : void } ;
You can’t perform that action at this time.
0 commit comments