Skip to content

Conversation

@Andarist
Copy link
Contributor

fixes #50832

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 18, 2022
// 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.

@sandersn sandersn self-assigned this Oct 17, 2022
@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 17, 2022
@sandersn sandersn requested a review from andrewbranch October 17, 2022 23:38
@RyanCavanaugh RyanCavanaugh merged commit 85d405a into microsoft:main Oct 18, 2022
@Andarist Andarist deleted the fix/await-mixed-generic-union branch October 18, 2022 22:15
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

False positive "await has no effect on the type" diagnostic with mixed generic union

5 participants