Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17200,7 +17200,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
// Always substitute on type parameters, regardless of variance, since even
// in contravariant positions, they may rely on substituted constraints to be valid
if ((covariant || type.flags & TypeFlags.TypeVariable) && parent.kind === SyntaxKind.ConditionalType && node === (parent as ConditionalTypeNode).trueType) {
if ((covariant || type.flags & TypeFlags.TypeVariable) && parent.kind === SyntaxKind.ConditionalType && node === (parent as ConditionalTypeNode).trueType && !getInferTypeParameters(parent as ConditionalTypeNode)) {
const constraint = getImpliedConstraint(type, (parent as ConditionalTypeNode).checkType, (parent as ConditionalTypeNode).extendsType);
if (constraint) {
constraints = append(constraints, constraint);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//// [tests/cases/compiler/distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts] ////

=== distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts ===
// https://github.com/microsoft/TypeScript/issues/62761

type Value = 1 | 2
>Value : Symbol(Value, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 0, 0))

type Result = [Value] extends [infer V]
>Result : Symbol(Result, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 2, 18))
>Value : Symbol(Value, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 0, 0))
>V : Symbol(V, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 4, 36))

? V extends unknown
>V : Symbol(V, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 4, 36))

? [V, Value]
>V : Symbol(V, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 4, 36))
>Value : Symbol(Value, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 0, 0))

: never
: never

type Value2 = { prop: 1 | 2 };
>Value2 : Symbol(Value2, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 8, 9))
>prop : Symbol(prop, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 10, 15))

type Result2 = Value2 extends { prop: infer V }
>Result2 : Symbol(Result2, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 10, 30))
>Value2 : Symbol(Value2, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 8, 9))
>prop : Symbol(prop, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 12, 31))
>V : Symbol(V, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 12, 43))

? V extends unknown
>V : Symbol(V, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 12, 43))

? [V, Value2]
>V : Symbol(V, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 12, 43))
>Value2 : Symbol(Value2, Decl(distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts, 8, 9))

: never
: never;

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [tests/cases/compiler/distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts] ////

=== distributiveConditionalTypeNoConstraintLeakThroughInferTypeParameter1.ts ===
// https://github.com/microsoft/TypeScript/issues/62761

type Value = 1 | 2
>Value : Value
> : ^^^^^

type Result = [Value] extends [infer V]
>Result : [1, Value] | [2, Value]
> : ^^^^^^^^^^^^^^^^^^^^^^^

? V extends unknown
? [V, Value]
: never
: never

type Value2 = { prop: 1 | 2 };
>Value2 : Value2
> : ^^^^^^
>prop : 1 | 2
> : ^^^^^

type Result2 = Value2 extends { prop: infer V }
>Result2 : [1, Value2] | [2, Value2]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>prop : V
> : ^

? V extends unknown
? [V, Value2]
: never
: never;

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @strict: true
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/62761

type Value = 1 | 2

type Result = [Value] extends [infer V]
? V extends unknown
? [V, Value]
: never
: never

type Value2 = { prop: 1 | 2 };

type Result2 = Value2 extends { prop: infer V }
? V extends unknown
? [V, Value2]
: never
: never;
Loading