We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents c9ccf72 + a7437fd commit 22fbb8eCopy full SHA for 22fbb8e
7 files changed
src/compiler/checker.ts
@@ -7245,7 +7245,7 @@ namespace ts {
7245
7246
function getConstrainedTypeParameter(typeParameter: TypeParameter, node: Node) {
7247
let constraints: Type[];
7248
- while (isTypeNode(node)) {
+ while (isPartOfTypeNode(node)) {
7249
const parent = node.parent;
7250
if (parent.kind === SyntaxKind.ConditionalType && node === (<ConditionalTypeNode>parent).trueType) {
7251
if (getTypeFromTypeNode((<ConditionalTypeNode>parent).checkType) === typeParameter) {
src/compiler/utilities.ts
@@ -771,6 +771,8 @@ namespace ts {
771
return node.parent.kind !== SyntaxKind.VoidExpression;
772
case SyntaxKind.ExpressionWithTypeArguments:
773
return !isExpressionWithTypeArgumentsInClassExtendsClause(node);
774
+ case SyntaxKind.TypeParameter:
775
+ return node.parent.kind === SyntaxKind.MappedType || node.parent.kind === SyntaxKind.InferType;
776
777
// Identifiers and qualified names may be type nodes, depending on their context. Climb
778
// above them to find the lowest container
tests/baselines/reference/inferTypes1.errors.txt
@@ -12,9 +12,10 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(72,43): error TS2304: C
12
tests/cases/conformance/types/conditional/inferTypes1.ts(72,43): error TS4081: Exported type alias 'T62' has or is using private name 'U'.
13
tests/cases/conformance/types/conditional/inferTypes1.ts(78,44): error TS2344: Type 'U' does not satisfy the constraint 'string'.
14
Type 'number' is not assignable to type 'string'.
15
+tests/cases/conformance/types/conditional/inferTypes1.ts(131,40): error TS2322: Type 'T' is not assignable to type 'string'.
16
17
-==== tests/cases/conformance/types/conditional/inferTypes1.ts (12 errors) ====
18
+==== tests/cases/conformance/types/conditional/inferTypes1.ts (13 errors) ====
19
type Unpacked<T> =
20
T extends (infer U)[] ? U :
21
T extends (...args: any[]) => infer U ? U :
@@ -167,4 +168,11 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(78,44): error TS2344: T
167
168
type A2<T, U extends void> = [T, U];
169
type B2<S> = S extends A2<infer T, infer U> ? [T, U] : never;
170
type C2<S, U extends void> = S extends A2<infer T, U> ? [T, U] : never;
171
+
172
+ // Repro from #21735
173
174
+ type A<T> = T extends string ? { [P in T]: void; } : T;
175
+ type B<T> = string extends T ? { [P in T]: void; } : T; // Error
176
+ ~
177
+!!! error TS2322: Type 'T' is not assignable to type 'string'.
178
tests/baselines/reference/inferTypes1.js
@@ -125,6 +125,11 @@ type B1<S> = S extends A1<infer T, infer U> ? [T, U] : never;
125
126
127
128
129
+// Repro from #21735
130
131
+type A<T> = T extends string ? { [P in T]: void; } : T;
132
+type B<T> = string extends T ? { [P in T]: void; } : T; // Error
133
134
135
//// [inferTypes1.js]
tests/baselines/reference/inferTypes1.symbols
@@ -551,3 +551,21 @@ type C2<S, U extends void> = S extends A2<infer T, U> ? [T, U] : never;
551
>T : Symbol(T, Decl(inferTypes1.ts, 125, 47))
552
>U : Symbol(U, Decl(inferTypes1.ts, 125, 10))
553
554
555
556
557
+>A : Symbol(A, Decl(inferTypes1.ts, 125, 71))
558
+>T : Symbol(T, Decl(inferTypes1.ts, 129, 7))
559
560
+>P : Symbol(P, Decl(inferTypes1.ts, 129, 34))
561
562
563
564
565
+>B : Symbol(B, Decl(inferTypes1.ts, 129, 55))
566
+>T : Symbol(T, Decl(inferTypes1.ts, 130, 7))
567
568
+>P : Symbol(P, Decl(inferTypes1.ts, 130, 34))
569
570
571
tests/baselines/reference/inferTypes1.types
@@ -558,3 +558,21 @@ type C2<S, U extends void> = S extends A2<infer T, U> ? [T, U] : never;
>T : T
>U : U
+>A : A<T>
+>T : T
+>P : P
572
+>B : B<T>
573
574
575
576
577
578
tests/cases/conformance/types/conditional/inferTypes1.ts
@@ -127,3 +127,8 @@ type B1<S> = S extends A1<infer T, infer U> ? [T, U] : never;
0 commit comments