Contextually type 'await ...' whose value is unused to 'void | PromiseLike<void>' #40162
Open
4 of 5 tasks
Labels
Experimentation Needed
Someone needs to try this out to see what happens
Suggestion
An idea for TypeScript
Search Terms
contextual type await void
Suggestion
When contextually typing an
await
whose expression is unused, we should use the contextual type ofvoid
:A statement like
await new Promise(...)
is commonly used to adapt a callback-based API where the result isn't value (such as Node'sfs.writeFile
). Once #39817 merges, thevalue
argument for theresolve
callback will no longer be optional unless it containsvoid
. Since the result of theawait
expression above is unused, we should usevoid
as the contextual type for theawait
, so that the contextual type for its operand becomesvoid | PromiseLike<void>
, thus contextually typing thePromise
construction.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: