return baseType in getSubstitutionType when baseType is any (#52573)

This commit is contained in:
Tobias S
2023-02-03 08:35:10 -08:00
committed by GitHub
parent bbfb9ac14f
commit 066c78d590
5 changed files with 48 additions and 1 deletions
+1 -1
View File
@@ -15227,7 +15227,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function getSubstitutionType(baseType: Type, constraint: Type) {
if (constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType) {
if (constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType || baseType.flags & TypeFlags.Any) {
return baseType;
}
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
@@ -0,0 +1,11 @@
//// [conditionalTypeAnyUnion.ts]
// repro from #52568
type Spec = any extends object ? any : string;
type WithSpec<T extends number> = T
type R = WithSpec<Spec> // should not error
//// [conditionalTypeAnyUnion.js]
// repro from #52568
@@ -0,0 +1,16 @@
=== tests/cases/compiler/conditionalTypeAnyUnion.ts ===
// repro from #52568
type Spec = any extends object ? any : string;
>Spec : Symbol(Spec, Decl(conditionalTypeAnyUnion.ts, 0, 0))
type WithSpec<T extends number> = T
>WithSpec : Symbol(WithSpec, Decl(conditionalTypeAnyUnion.ts, 2, 46))
>T : Symbol(T, Decl(conditionalTypeAnyUnion.ts, 4, 14))
>T : Symbol(T, Decl(conditionalTypeAnyUnion.ts, 4, 14))
type R = WithSpec<Spec> // should not error
>R : Symbol(R, Decl(conditionalTypeAnyUnion.ts, 4, 35))
>WithSpec : Symbol(WithSpec, Decl(conditionalTypeAnyUnion.ts, 2, 46))
>Spec : Symbol(Spec, Decl(conditionalTypeAnyUnion.ts, 0, 0))
@@ -0,0 +1,12 @@
=== tests/cases/compiler/conditionalTypeAnyUnion.ts ===
// repro from #52568
type Spec = any extends object ? any : string;
>Spec : any
type WithSpec<T extends number> = T
>WithSpec : T
type R = WithSpec<Spec> // should not error
>R : any
@@ -0,0 +1,8 @@
// repro from #52568
type Spec = any extends object ? any : string;
type WithSpec<T extends number> = T
type R = WithSpec<Spec> // should not error