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

This commit is contained in:
Tobias S
2023-02-03 17:35:10 +01:00
committed by GitHub
parent bbfb9ac14f
commit 066c78d590
5 changed files with 48 additions and 1 deletions

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)}`;

View File

@@ -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

View File

@@ -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))

View File

@@ -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

View File

@@ -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