From 3f6afe39570117b33c8531cccf034ac0a1cfbb7c Mon Sep 17 00:00:00 2001 From: Tobias Scholz Date: Thu, 2 Feb 2023 17:23:19 +0100 Subject: [PATCH] return baseType in getSubstitutionType when baseType is any --- src/compiler/checker.ts | 2 +- .../reference/conditionalTypeAnyUnion.js | 11 +++++++++++ .../reference/conditionalTypeAnyUnion.symbols | 16 ++++++++++++++++ .../reference/conditionalTypeAnyUnion.types | 12 ++++++++++++ tests/cases/compiler/conditionalTypeAnyUnion.ts | 8 ++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/conditionalTypeAnyUnion.js create mode 100644 tests/baselines/reference/conditionalTypeAnyUnion.symbols create mode 100644 tests/baselines/reference/conditionalTypeAnyUnion.types create mode 100644 tests/cases/compiler/conditionalTypeAnyUnion.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 31d47473b6c4e..ba337462642ef 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15217,7 +15217,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)}`; diff --git a/tests/baselines/reference/conditionalTypeAnyUnion.js b/tests/baselines/reference/conditionalTypeAnyUnion.js new file mode 100644 index 0000000000000..611c0eac9da15 --- /dev/null +++ b/tests/baselines/reference/conditionalTypeAnyUnion.js @@ -0,0 +1,11 @@ +//// [conditionalTypeAnyUnion.ts] +// repro from #52568 + +type Spec = any extends object ? any : string; + +type WithSpec = T + +type R = WithSpec // should not error + +//// [conditionalTypeAnyUnion.js] +// repro from #52568 diff --git a/tests/baselines/reference/conditionalTypeAnyUnion.symbols b/tests/baselines/reference/conditionalTypeAnyUnion.symbols new file mode 100644 index 0000000000000..67b26e6a43570 --- /dev/null +++ b/tests/baselines/reference/conditionalTypeAnyUnion.symbols @@ -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 +>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 // 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)) + diff --git a/tests/baselines/reference/conditionalTypeAnyUnion.types b/tests/baselines/reference/conditionalTypeAnyUnion.types new file mode 100644 index 0000000000000..155d6b4bc92db --- /dev/null +++ b/tests/baselines/reference/conditionalTypeAnyUnion.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/conditionalTypeAnyUnion.ts === +// repro from #52568 + +type Spec = any extends object ? any : string; +>Spec : any + +type WithSpec = T +>WithSpec : T + +type R = WithSpec // should not error +>R : any + diff --git a/tests/cases/compiler/conditionalTypeAnyUnion.ts b/tests/cases/compiler/conditionalTypeAnyUnion.ts new file mode 100644 index 0000000000000..22c7b936657da --- /dev/null +++ b/tests/cases/compiler/conditionalTypeAnyUnion.ts @@ -0,0 +1,8 @@ + +// repro from #52568 + +type Spec = any extends object ? any : string; + +type WithSpec = T + +type R = WithSpec // should not error \ No newline at end of file