Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36923,7 +36923,7 @@ namespace ts {
// We only need `Awaited<T>` 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) :
Copy link
Contributor Author

@Andarist Andarist Sep 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative fix would be to move someType to isThenableType:

patch
diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 088ba325ec..89cfb6bcae 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -36884,8 +36884,10 @@ namespace ts { return false; } - const thenFunction = getTypeOfPropertyOfType(type, "then" as __String); - return !!thenFunction && getSignaturesOfType(getTypeWithFacts(thenFunction, TypeFacts.NEUndefinedOrNull), SignatureKind.Call).length > 0; + return someType(type, t => { + const thenFunction = getTypeOfPropertyOfType(t, "then" as __String); + return !!thenFunction && getSignaturesOfType(getTypeWithFacts(thenFunction, TypeFacts.NEUndefinedOrNull), SignatureKind.Call).length > 0; + }); } interface AwaitedTypeInstantiation extends Type { @@ -36923,7 +36925,7 @@ namespace ts { // We only need `Awaited<T>` 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) || someType(baseConstraint, isThenableType) : + baseConstraint.flags & TypeFlags.AnyOrUnknown || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint) : maybeTypeOfKind(type, TypeFlags.TypeVariable)) { return true; }

That would in turn impact the other call site to this util, here, and I'm not sure if that's desirable.

maybeTypeOfKind(type, TypeFlags.TypeVariable)) {
return true;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/cases/fourslash/codeFixRemoveUnnecessaryAwait_mixedUnion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />

// @target: esnext
//// async function fn1(a: Promise<void> | void) {
//// await a;
//// }
////
//// async function fn2<T extends Promise<void> | void>(a: T) {
//// await a;
//// }

verify.getSuggestionDiagnostics([]);