You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Contextually type 'await ...' whose value is unused to 'void | PromiseLike<void>' #40162
A statement like await new Promise(...) is commonly used to adapt a callback-based API where the result isn't value (such as Node's fs.writeFile). Once #39817 merges, the value argument for the resolve callback will no longer be optional unless it contains void. Since the result of the await expression above is unused, we should use void as the contextual type for the await, so that the contextual type for its operand becomes void | PromiseLike<void>, thus contextually typing the Promise construction.
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code:
This will require testing to verify
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
This would be super nice! For example, we have docs that encourage the pattern await new Promise(resolve => server.listen(PORT, resolve)). It would be nice if this worked without <void>, especially because it would enable the same code to work in JS and TS.
Activity
glasser commentedon Oct 21, 2021
This would be super nice! For example, we have docs that encourage the pattern
await new Promise(resolve => server.listen(PORT, resolve)). It would be nice if this worked without<void>, especially because it would enable the same code to work in JS and TS.docs: provide TS versions of examples with `await new Promise`
docs: provide TS versions of examples with `await new Promise` (#5825)