Skip to content

Commit 0519dfa

Browse files
committed
Fixed an issue with constraint of an infer type parameter not being fully instantiatable
1 parent 6947c98 commit 0519dfa

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17789,7 +17789,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1778917789

1779017790
function maybeCloneTypeParameter(p: TypeParameter) {
1779117791
const constraint = getConstraintOfTypeParameter(p);
17792-
return constraint && (isGenericObjectType(constraint) || isGenericIndexType(constraint)) ? cloneTypeParameter(p) : p;
17792+
return constraint && couldContainTypeVariables(constraint) ? cloneTypeParameter(p) : p;
1779317793
}
1779417794

1779517795
function isSimpleTupleType(node: TypeNode) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/types/conditional/inferTypesWithExtendsDependingOnTypeVariables.ts ===
2+
// repro from https://github.com/microsoft/TypeScript/issues/54197
3+
4+
type Bar<K, T extends readonly unknown[]> = T extends readonly [any, ...infer X extends readonly K[]] ? X : never;
5+
>Bar : Symbol(Bar, Decl(inferTypesWithExtendsDependingOnTypeVariables.ts, 0, 0))
6+
>K : Symbol(K, Decl(inferTypesWithExtendsDependingOnTypeVariables.ts, 2, 9))
7+
>T : Symbol(T, Decl(inferTypesWithExtendsDependingOnTypeVariables.ts, 2, 11))
8+
>T : Symbol(T, Decl(inferTypesWithExtendsDependingOnTypeVariables.ts, 2, 11))
9+
>X : Symbol(X, Decl(inferTypesWithExtendsDependingOnTypeVariables.ts, 2, 77))
10+
>K : Symbol(K, Decl(inferTypesWithExtendsDependingOnTypeVariables.ts, 2, 9))
11+
>X : Symbol(X, Decl(inferTypesWithExtendsDependingOnTypeVariables.ts, 2, 77))
12+
13+
type Res1 = Bar<"a" | "b", ["a", "b", "b"]>
14+
>Res1 : Symbol(Res1, Decl(inferTypesWithExtendsDependingOnTypeVariables.ts, 2, 114))
15+
>Bar : Symbol(Bar, Decl(inferTypesWithExtendsDependingOnTypeVariables.ts, 0, 0))
16+
17+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/conformance/types/conditional/inferTypesWithExtendsDependingOnTypeVariables.ts ===
2+
// repro from https://github.com/microsoft/TypeScript/issues/54197
3+
4+
type Bar<K, T extends readonly unknown[]> = T extends readonly [any, ...infer X extends readonly K[]] ? X : never;
5+
>Bar : Bar<K, T>
6+
7+
type Res1 = Bar<"a" | "b", ["a", "b", "b"]>
8+
>Res1 : ["b", "b"]
9+
10+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// repro from https://github.com/microsoft/TypeScript/issues/54197
5+
6+
type Bar<K, T extends readonly unknown[]> = T extends readonly [any, ...infer X extends readonly K[]] ? X : never;
7+
type Res1 = Bar<"a" | "b", ["a", "b", "b"]>
8+

0 commit comments

Comments
 (0)