Skip to content

Commit 066c78d

Browse files
return baseType in getSubstitutionType when baseType is any (#52573)
1 parent bbfb9ac commit 066c78d

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

src/compiler/checker.ts

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

1522915229
function getSubstitutionType(baseType: Type, constraint: Type) {
15230-
if (constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType) {
15230+
if (constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType || baseType.flags & TypeFlags.Any) {
1523115231
return baseType;
1523215232
}
1523315233
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [conditionalTypeAnyUnion.ts]
2+
// repro from #52568
3+
4+
type Spec = any extends object ? any : string;
5+
6+
type WithSpec<T extends number> = T
7+
8+
type R = WithSpec<Spec> // should not error
9+
10+
//// [conditionalTypeAnyUnion.js]
11+
// repro from #52568
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/conditionalTypeAnyUnion.ts ===
2+
// repro from #52568
3+
4+
type Spec = any extends object ? any : string;
5+
>Spec : Symbol(Spec, Decl(conditionalTypeAnyUnion.ts, 0, 0))
6+
7+
type WithSpec<T extends number> = T
8+
>WithSpec : Symbol(WithSpec, Decl(conditionalTypeAnyUnion.ts, 2, 46))
9+
>T : Symbol(T, Decl(conditionalTypeAnyUnion.ts, 4, 14))
10+
>T : Symbol(T, Decl(conditionalTypeAnyUnion.ts, 4, 14))
11+
12+
type R = WithSpec<Spec> // should not error
13+
>R : Symbol(R, Decl(conditionalTypeAnyUnion.ts, 4, 35))
14+
>WithSpec : Symbol(WithSpec, Decl(conditionalTypeAnyUnion.ts, 2, 46))
15+
>Spec : Symbol(Spec, Decl(conditionalTypeAnyUnion.ts, 0, 0))
16+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/conditionalTypeAnyUnion.ts ===
2+
// repro from #52568
3+
4+
type Spec = any extends object ? any : string;
5+
>Spec : any
6+
7+
type WithSpec<T extends number> = T
8+
>WithSpec : T
9+
10+
type R = WithSpec<Spec> // should not error
11+
>R : any
12+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
// repro from #52568
3+
4+
type Spec = any extends object ? any : string;
5+
6+
type WithSpec<T extends number> = T
7+
8+
type R = WithSpec<Spec> // should not error

0 commit comments

Comments
 (0)