From 85d405a1d74c0730a9d8d6307b26e8d6f3f75421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 18 Oct 2022 23:10:03 +0200 Subject: [PATCH] Fixed a false positive "await has no effect on the type" diagnostic with mixed generic union (#50833) --- src/compiler/checker.ts | 2 +- .../codeFixRemoveUnnecessaryAwait_mixedUnion.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/codeFixRemoveUnnecessaryAwait_mixedUnion.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 94e891ea255a9..ee02a3532eb3a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37104,7 +37104,7 @@ namespace ts { // We only need `Awaited` if `T` is a type variable that has no base constraint, or the base constraint of `T` is `any`, `unknown`, `{}`, `object`, // or is promise-like. if (baseConstraint ? - baseConstraint.flags & TypeFlags.AnyOrUnknown || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint) : + baseConstraint.flags & TypeFlags.AnyOrUnknown || isEmptyObjectType(baseConstraint) || someType(baseConstraint, isThenableType) : maybeTypeOfKind(type, TypeFlags.TypeVariable)) { return true; } diff --git a/tests/cases/fourslash/codeFixRemoveUnnecessaryAwait_mixedUnion.ts b/tests/cases/fourslash/codeFixRemoveUnnecessaryAwait_mixedUnion.ts new file mode 100644 index 0000000000000..605e5b97481aa --- /dev/null +++ b/tests/cases/fourslash/codeFixRemoveUnnecessaryAwait_mixedUnion.ts @@ -0,0 +1,12 @@ +/// + +// @target: esnext +//// async function fn1(a: Promise | void) { +//// await a; +//// } +//// +//// async function fn2 | void>(a: T) { +//// await a; +//// } + +verify.getSuggestionDiagnostics([]);