"'await' has no effect on the type of this expression" from inferred void
and Promise<void>
union
#55456
Labels
Design Limitation
Constraints of the existing architecture prevent this from being fixed
🔎 Search Terms
"'await' has no effect on the type of this expression" , "promise<void>"
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.2.1-rc#code/MYewdgzgLgBGIgA4wLwwBQEpUD4YG8BfAbgChSBDCATzGBgDMBXOqAS3EYXQYBsKA5gC4YAIwS8AphTDZ8pGDFCRYkgB6TgTKJNSN+AmAH4YVWvSy4CMAPQAqGABMQMdYkmQ2AN10B3EABOANYwdjYwhDAi8EhkihS+FGyqGlo6WGSEpEA
💻 Code
🙁 Actual behavior
The type of
execute
is inferred as() => void
, so TypeScript displays a spurious warning on theawait execute();
line, "'await' has no effect on the type of this expression.(80007)".🙂 Expected behavior
TypeScript infers the type as
() => void | () => Promise<void>
, and callingawait execute()
generates no warnings.Based on the FAQ, I would expect explicitly assigning
() => Promise<void>
to() => void
to work, but I would not expect() => void | () => Promise<void>
to be inferred as() => void
and correct code then generating compiler diagnostics.Additional information about the issue
I found some possibly related issues: #44201, #43921, #49755
If this issue is actually a duplicate of one of those, I apologize.
The text was updated successfully, but these errors were encountered: