File tree Expand file tree Collapse file tree 3 files changed +121
-0
lines changed Expand file tree Collapse file tree 3 files changed +121
-0
lines changed Original file line number Diff line number Diff line change
1
+ tests/cases/compiler/mappedTypeIndexedAccess.ts(18,5): error TS2322: Type '{ key: "foo"; value: number; }' is not assignable to type '{ key: "foo"; value: string; } | { key: "bar"; value: number; }'.
2
+ Type '{ key: "foo"; value: number; }' is not assignable to type '{ key: "foo"; value: string; }'.
3
+ Types of property 'value' are incompatible.
4
+ Type 'number' is not assignable to type 'string'.
5
+ tests/cases/compiler/mappedTypeIndexedAccess.ts(24,5): error TS2322: Type '{ key: "foo"; value: number; }' is not assignable to type '{ key: "foo"; value: string; } | { key: "bar"; value: number; }'.
6
+ Type '{ key: "foo"; value: number; }' is not assignable to type '{ key: "foo"; value: string; }'.
7
+ Types of property 'value' are incompatible.
8
+ Type 'number' is not assignable to type 'string'.
9
+
10
+
11
+ ==== tests/cases/compiler/mappedTypeIndexedAccess.ts (2 errors) ====
12
+ // Repro from #15756
13
+
14
+ type Pairs<T> = {
15
+ [TKey in keyof T]: {
16
+ key: TKey;
17
+ value: T[TKey];
18
+ };
19
+ };
20
+
21
+ type Pair<T> = Pairs<T>[keyof T];
22
+
23
+ type FooBar = {
24
+ foo: string;
25
+ bar: number;
26
+ };
27
+
28
+ // Error expected here
29
+ let pair1: Pair<FooBar> = {
30
+ ~~~~~
31
+ !!! error TS2322: Type '{ key: "foo"; value: number; }' is not assignable to type '{ key: "foo"; value: string; } | { key: "bar"; value: number; }'.
32
+ !!! error TS2322: Type '{ key: "foo"; value: number; }' is not assignable to type '{ key: "foo"; value: string; }'.
33
+ !!! error TS2322: Types of property 'value' are incompatible.
34
+ !!! error TS2322: Type 'number' is not assignable to type 'string'.
35
+ key: "foo",
36
+ value: 3
37
+ };
38
+
39
+ // Error expected here
40
+ let pair2: Pairs<FooBar>[keyof FooBar] = {
41
+ ~~~~~
42
+ !!! error TS2322: Type '{ key: "foo"; value: number; }' is not assignable to type '{ key: "foo"; value: string; } | { key: "bar"; value: number; }'.
43
+ !!! error TS2322: Type '{ key: "foo"; value: number; }' is not assignable to type '{ key: "foo"; value: string; }'.
44
+ !!! error TS2322: Types of property 'value' are incompatible.
45
+ !!! error TS2322: Type 'number' is not assignable to type 'string'.
46
+ key: "foo",
47
+ value: 3
48
+ };
49
+
Original file line number Diff line number Diff line change
1
+ //// [mappedTypeIndexedAccess.ts]
2
+ // Repro from #15756
3
+
4
+ type Pairs < T > = {
5
+ [ TKey in keyof T ] : {
6
+ key : TKey ;
7
+ value: T [ TKey ] ;
8
+ } ;
9
+ } ;
10
+
11
+ type Pair < T > = Pairs < T > [ keyof T ] ;
12
+
13
+ type FooBar = {
14
+ foo : string ;
15
+ bar: number ;
16
+ } ;
17
+
18
+ // Error expected here
19
+ let pair1 : Pair < FooBar > = {
20
+ key : "foo" ,
21
+ value : 3
22
+ } ;
23
+
24
+ // Error expected here
25
+ let pair2 : Pairs < FooBar > [ keyof FooBar ] = {
26
+ key : "foo" ,
27
+ value : 3
28
+ } ;
29
+
30
+
31
+ //// [mappedTypeIndexedAccess.js]
32
+ "use strict" ;
33
+ // Repro from #15756
34
+ // Error expected here
35
+ var pair1 = {
36
+ key : "foo" ,
37
+ value : 3
38
+ } ;
39
+ // Error expected here
40
+ var pair2 = {
41
+ key : "foo" ,
42
+ value : 3
43
+ } ;
Original file line number Diff line number Diff line change
1
+ // @strict : true
2
+
3
+ // Repro from #15756
4
+
5
+ type Pairs < T > = {
6
+ [ TKey in keyof T ] : {
7
+ key : TKey ;
8
+ value : T [ TKey ] ;
9
+ } ;
10
+ } ;
11
+
12
+ type Pair < T > = Pairs < T > [ keyof T ] ;
13
+
14
+ type FooBar = {
15
+ foo : string ;
16
+ bar : number ;
17
+ } ;
18
+
19
+ // Error expected here
20
+ let pair1 : Pair < FooBar > = {
21
+ key : "foo" ,
22
+ value : 3
23
+ } ;
24
+
25
+ // Error expected here
26
+ let pair2 : Pairs < FooBar > [ keyof FooBar ] = {
27
+ key : "foo" ,
28
+ value : 3
29
+ } ;
You can’t perform that action at this time.
0 commit comments