You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mappedTypeConstraints2.ts(10,11): error TS2322: Type 'Mapped2<K>[`get${K}`]' is not assignable to type '{ a: K; }'.
2
-
Type '{ a: `get${K}`; }' is not assignable to type '{ a: K; }'.
3
-
Types of property 'a' are incompatible.
4
-
Type '`get${K}`' is not assignable to type 'K'.
5
-
'`get${K}`' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
6
-
Type '`get${string}`' is not assignable to type 'K'.
7
-
'`get${string}`' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
2
+
Type 'Mapped2<K>[`get${string}`]' is not assignable to type '{ a: K; }'.
8
3
mappedTypeConstraints2.ts(16,11): error TS2322: Type 'Mapped3<K>[Uppercase<K>]' is not assignable to type '{ a: K; }'.
9
-
Type '{ a: Uppercase<K>; }' is not assignable to type '{ a: K; }'.
10
-
Types of property 'a' are incompatible.
11
-
Type 'Uppercase<K>' is not assignable to type 'K'.
12
-
'Uppercase<K>' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
13
-
Type 'Uppercase<string>' is not assignable to type 'K'.
14
-
'Uppercase<string>' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
15
-
Type 'string' is not assignable to type 'K'.
16
-
'string' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
4
+
Type 'Mapped3<K>[Uppercase<string>]' is not assignable to type '{ a: K; }'.
5
+
Type 'Mapped3<K>[string]' is not assignable to type '{ a: K; }'.
17
6
mappedTypeConstraints2.ts(25,57): error TS2322: Type 'Foo<T>[`get${T}`]' is not assignable to type 'T'.
18
-
'Foo<T>[`get${T}`]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
19
-
Type '`get${T}`' is not assignable to type 'T'.
20
-
'`get${T}`' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
21
-
Type '`get${string}`' is not assignable to type 'T'.
22
-
'`get${string}`' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
7
+
'T' could be instantiated with an arbitrary type which could be unrelated to 'Foo<T>[`get${T}`]'.
23
8
24
9
25
10
==== mappedTypeConstraints2.ts (3 errors) ====
@@ -35,12 +20,7 @@ mappedTypeConstraints2.ts(25,57): error TS2322: Type 'Foo<T>[`get${T}`]' is not
35
20
const x: { a: K } = obj[key]; // Error
36
21
~
37
22
!!! error TS2322: Type 'Mapped2<K>[`get${K}`]' is not assignable to type '{ a: K; }'.
38
-
!!! error TS2322: Type '{ a: `get${K}`; }' is not assignable to type '{ a: K; }'.
39
-
!!! error TS2322: Types of property 'a' are incompatible.
40
-
!!! error TS2322: Type '`get${K}`' is not assignable to type 'K'.
41
-
!!! error TS2322: '`get${K}`' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
42
-
!!! error TS2322: Type '`get${string}`' is not assignable to type 'K'.
43
-
!!! error TS2322: '`get${string}`' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
23
+
!!! error TS2322: Type 'Mapped2<K>[`get${string}`]' is not assignable to type '{ a: K; }'.
44
24
}
45
25
46
26
type Mapped3<K extends string> = { [P in K as Uppercase<P>]: { a: P } };
@@ -49,14 +29,8 @@ mappedTypeConstraints2.ts(25,57): error TS2322: Type 'Foo<T>[`get${T}`]' is not
49
29
const x: { a: K } = obj[key]; // Error
50
30
~
51
31
!!! error TS2322: Type 'Mapped3<K>[Uppercase<K>]' is not assignable to type '{ a: K; }'.
52
-
!!! error TS2322: Type '{ a: Uppercase<K>; }' is not assignable to type '{ a: K; }'.
53
-
!!! error TS2322: Types of property 'a' are incompatible.
54
-
!!! error TS2322: Type 'Uppercase<K>' is not assignable to type 'K'.
55
-
!!! error TS2322: 'Uppercase<K>' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
56
-
!!! error TS2322: Type 'Uppercase<string>' is not assignable to type 'K'.
57
-
!!! error TS2322: 'Uppercase<string>' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
58
-
!!! error TS2322: Type 'string' is not assignable to type 'K'.
59
-
!!! error TS2322: 'string' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
32
+
!!! error TS2322: Type 'Mapped3<K>[Uppercase<string>]' is not assignable to type '{ a: K; }'.
33
+
!!! error TS2322: Type 'Mapped3<K>[string]' is not assignable to type '{ a: K; }'.
60
34
}
61
35
62
36
// Repro from #47794
@@ -68,11 +42,7 @@ mappedTypeConstraints2.ts(25,57): error TS2322: Type 'Foo<T>[`get${T}`]' is not
68
42
const get = <T extends string>(t: T, foo: Foo<T>): T => foo[`get${t}`]; // Type 'Foo<T>[`get${T}`]' is not assignable to type 'T'
69
43
~~~~~~~~~~~~~~
70
44
!!! error TS2322: Type 'Foo<T>[`get${T}`]' is not assignable to type 'T'.
71
-
!!! error TS2322: 'Foo<T>[`get${T}`]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
72
-
!!! error TS2322: Type '`get${T}`' is not assignable to type 'T'.
73
-
!!! error TS2322: '`get${T}`' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
74
-
!!! error TS2322: Type '`get${string}`' is not assignable to type 'T'.
75
-
!!! error TS2322: '`get${string}`' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
45
+
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Foo<T>[`get${T}`]'.
76
46
77
47
// Repro from #48626
78
48
@@ -95,14 +65,4 @@ mappedTypeConstraints2.ts(25,57): error TS2322: Type 'Foo<T>[`get${T}`]' is not
95
65
}
96
66
return true;
97
67
}
98
-
99
-
// repro from #50030
100
-
101
-
type ObjectWithUnderscoredKeys<K extends string> = {
102
-
[k in K as `_${k}`]: true;
103
-
};
104
-
105
-
function genericTest<K extends string>(objectWithUnderscoredKeys: ObjectWithUnderscoredKeys<K>, key: K) {
0 commit comments