File tree Expand file tree Collapse file tree
cases/conformance/types/mapped Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(9,30): error TS2536: Type 'K' cannot be used to index type 'T1<K>'.
2+ tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(13,30): error TS2536: Type 'K' cannot be used to index type 'T3'.
3+ tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(15,47): error TS2536: Type 'S' cannot be used to index type 'AB'.
4+ tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(17,49): error TS2536: Type 'L' cannot be used to index type '{ [key in AB[S]]: true; }'.
5+
6+
7+ ==== tests/cases/conformance/types/mapped/mappedTypeErrors2.ts (4 errors) ====
8+ // Repros from #17238
9+
10+ type AB = {
11+ a: 'a'
12+ b: 'a'
13+ };
14+
15+ type T1<K extends keyof AB> = { [key in AB[K]]: true };
16+ type T2<K extends 'a'|'b'> = T1<K>[K]; // Error
17+ ~~~~~~~~
18+ !!! error TS2536: Type 'K' cannot be used to index type 'T1<K>'.
19+
20+ type R = AB[keyof AB]; // "a"
21+ type T3 = { [key in R]: true };
22+ type T4<K extends 'a'|'b'> = T3[K] // Error
23+ ~~~~~
24+ !!! error TS2536: Type 'K' cannot be used to index type 'T3'.
25+
26+ type T5<S extends 'a'|'b'|'extra'> = {[key in AB[S]]: true}[S]; // Error
27+ ~~~~~
28+ !!! error TS2536: Type 'S' cannot be used to index type 'AB'.
29+
30+ type T6<S extends 'a'|'b', L extends 'a'|'b'> = {[key in AB[S]]: true}[L]; // Error
31+ ~~~~~~~~~~~~~~~~~~~~~~~~~
32+ !!! error TS2536: Type 'L' cannot be used to index type '{ [key in AB[S]]: true; }'.
33+
34+ type T7<S extends 'a'|'b', L extends 'a'> = {[key in AB[S]]: true}[L];
35+
Original file line number Diff line number Diff line change 1+ //// [mappedTypeErrors2.ts]
2+ // Repros from #17238
3+
4+ type AB = {
5+ a : 'a'
6+ b : 'a'
7+ } ;
8+
9+ type T1 < K extends keyof AB > = { [ key in AB [ K ] ] : true } ;
10+ type T2 < K extends 'a' | 'b' > = T1 < K > [ K ] ; // Error
11+
12+ type R = AB [ keyof AB ] ; // "a"
13+ type T3 = { [ key in R ] : true } ;
14+ type T4 < K extends 'a' | 'b' > = T3 [ K ] // Error
15+
16+ type T5 < S extends 'a' | 'b' | 'extra' > = { [ key in AB [ S ] ] : true } [ S ] ; // Error
17+
18+ type T6 < S extends 'a' | 'b' , L extends 'a' | 'b' > = { [ key in AB [ S ] ] : true } [ L ] ; // Error
19+
20+ type T7 < S extends 'a' | 'b' , L extends 'a' > = { [ key in AB [ S ] ] : true } [ L ] ;
21+
22+
23+ //// [mappedTypeErrors2.js]
24+ // Repros from #17238
25+
26+
27+ //// [mappedTypeErrors2.d.ts]
28+ declare type AB = {
29+ a : 'a' ;
30+ b: 'a' ;
31+ } ;
32+ declare type T1 < K extends keyof AB > = {
33+ [ key in AB [ K ] ] : true ;
34+ } ;
35+ declare type T2 < K extends 'a' | 'b' > = T1 < K > [ K ] ;
36+ declare type R = AB [ keyof AB ] ;
37+ declare type T3 = {
38+ [ key in R ] : true ;
39+ } ;
40+ declare type T4 < K extends 'a' | 'b' > = T3 [ K ] ;
41+ declare type T5 < S extends 'a' | 'b' | 'extra' > = {
42+ [ key in AB [ S ] ] : true ;
43+ } [ S ] ;
44+ declare type T6 < S extends 'a' | 'b' , L extends 'a' | 'b' > = {
45+ [ key in AB [ S ] ] : true ;
46+ } [ L ] ;
47+ declare type T7 < S extends 'a' | 'b' , L extends 'a' > = {
48+ [ key in AB [ S ] ] : true ;
49+ } [ L ] ;
Original file line number Diff line number Diff line change 1+ // @strictNullChecks : true
2+ // @declaration : true
3+
4+ // Repros from #17238
5+
6+ type AB = {
7+ a : 'a'
8+ b : 'a'
9+ } ;
10+
11+ type T1 < K extends keyof AB > = { [ key in AB [ K ] ] : true } ;
12+ type T2 < K extends 'a' | 'b' > = T1 < K > [ K ] ; // Error
13+
14+ type R = AB [ keyof AB ] ; // "a"
15+ type T3 = { [ key in R ] : true } ;
16+ type T4 < K extends 'a' | 'b' > = T3 [ K ] // Error
17+
18+ type T5 < S extends 'a' | 'b' | 'extra' > = { [ key in AB [ S ] ] : true } [ S ] ; // Error
19+
20+ type T6 < S extends 'a' | 'b' , L extends 'a' | 'b' > = { [ key in AB [ S ] ] : true } [ L ] ; // Error
21+
22+ type T7 < S extends 'a' | 'b' , L extends 'a' > = { [ key in AB [ S ] ] : true } [ L ] ;
You can’t perform that action at this time.
0 commit comments