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'.
17
-
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'.
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; }'.
6
+
mappedTypeConstraints2.ts(42,7): error TS2322: Type 'Mapped6<K>[keyof Mapped6<K>]' is not assignable to type '`_${string}`'.
7
+
Type 'Mapped6<K>[string] | Mapped6<K>[number] | Mapped6<K>[symbol]' is not assignable to type '`_${string}`'.
8
+
Type 'Mapped6<K>[string]' is not assignable to type '`_${string}`'.
9
+
mappedTypeConstraints2.ts(51,57): error TS2322: Type 'Foo<T>[`get${T}`]' is not assignable to type 'T'.
10
+
'T' could be instantiated with an arbitrary type which could be unrelated to 'Foo<T>[`get${T}`]'.
11
+
mappedTypeConstraints2.ts(82,9): error TS2322: Type 'ObjectWithUnderscoredKeys<K>[`_${K}`]' is not assignable to type 'true'.
12
+
Type 'ObjectWithUnderscoredKeys<K>[`_${string}`]' is not assignable to type 'true'.
23
13
24
14
25
-
==== mappedTypeConstraints2.ts (3 errors) ====
15
+
==== mappedTypeConstraints2.ts (5 errors) ====
26
16
type Mapped1<K extends string> = { [P in K]: { a: P } };
27
17
28
18
function f1<K extends string>(obj: Mapped1<K>, key: K) {
@@ -35,12 +25,7 @@ mappedTypeConstraints2.ts(25,57): error TS2322: Type 'Foo<T>[`get${T}`]' is not
35
25
const x: { a: K } = obj[key]; // Error
36
26
~
37
27
!!! 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'.
28
+
!!! error TS2322: Type 'Mapped2<K>[`get${string}`]' is not assignable to type '{ a: K; }'.
44
29
}
45
30
46
31
type Mapped3<K extends string> = { [P in K as Uppercase<P>]: { a: P } };
@@ -49,14 +34,38 @@ mappedTypeConstraints2.ts(25,57): error TS2322: Type 'Foo<T>[`get${T}`]' is not
49
34
const x: { a: K } = obj[key]; // Error
50
35
~
51
36
!!! 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'.
37
+
!!! error TS2322: Type 'Mapped3<K>[Uppercase<string>]' is not assignable to type '{ a: K; }'.
38
+
!!! error TS2322: Type 'Mapped3<K>[string]' is not assignable to type '{ a: K; }'.
39
+
}
40
+
41
+
type Mapped4<K extends `_${string}`> = {
42
+
[P in K]: P;
43
+
};
44
+
45
+
function f4<K extends `_${string}`>(obj: Mapped4<K>, key: keyof Mapped4<K>) {
46
+
let s: `_${string}` = obj[key];
47
+
}
48
+
49
+
type Mapped5<K extends string> = {
50
+
[P in K as P extends `_${string}` ? P : never]: P;
51
+
};
52
+
53
+
function f5<K extends string>(obj: Mapped5<K>, key: keyof Mapped5<K>) {
54
+
let s: `_${string}` = obj[key];
55
+
}
56
+
57
+
// repro from #53066#issuecomment-1913384757
58
+
59
+
type Mapped6<K extends string> = {
60
+
[P in K as `_${P}`]: P;
61
+
};
62
+
63
+
function f6<K extends string>(obj: Mapped6<K>, key: keyof Mapped6<K>) {
64
+
let s: `_${string}` = obj[key]; // Error
65
+
~
66
+
!!! error TS2322: Type 'Mapped6<K>[keyof Mapped6<K>]' is not assignable to type '`_${string}`'.
67
+
!!! error TS2322: Type 'Mapped6<K>[string] | Mapped6<K>[number] | Mapped6<K>[symbol]' is not assignable to type '`_${string}`'.
68
+
!!! error TS2322: Type 'Mapped6<K>[string]' is not assignable to type '`_${string}`'.
60
69
}
61
70
62
71
// Repro from #47794
@@ -68,11 +77,7 @@ mappedTypeConstraints2.ts(25,57): error TS2322: Type 'Foo<T>[`get${T}`]' is not
68
77
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
78
~~~~~~~~~~~~~~
70
79
!!! 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'.
80
+
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Foo<T>[`get${T}`]'.
76
81
77
82
// Repro from #48626
78
83
@@ -103,6 +108,9 @@ mappedTypeConstraints2.ts(25,57): error TS2322: Type 'Foo<T>[`get${T}`]' is not
103
108
};
104
109
105
110
function genericTest<K extends string>(objectWithUnderscoredKeys: ObjectWithUnderscoredKeys<K>, key: K) {
0 commit comments