Return type inference error with async functions and Promise.reject()
See original GitHub issueTypeScript Version: 3.0.1
Code
async function often() {
if (false) {
return Promise.reject();
}
// code
}
let sometimes = often();
sometimes = Promise.resolve();
Actual behavior:
error TS2322: Type 'Promise<void>' is not assignable to type 'Promise<never>'.
Playground Link: here
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Why is Promise<never> not considered in reachability analysis?
Technically promises are asynchronous processes, meaning that the code after a promise continues to run while the promise itself is being ...
Read more >Error handling with Async/Await in JS | by Ian Segers | ITNEXT
Now we have the classic problem, thisThrows returns a rejecting promise, so the regular try...catch is not able to catch the error. As...
Read more >A quick introduction to “Promises” and “Async/Await” (with new ...
Similar to Promise.resolve static method, the Promise.reject(error) method always returns a rejected promise. The value of the promise rejection ...
Read more >Futures and error handling | Dart
Functions that use the Future API register callbacks that handle the value (or the error) that completes a Future. For example: myFunc().then(processValue).
Read more >async function returning Promise<void> successfully ... - Reddit
Removing async is a different error as because it's no longer returning a promise automatically, it doesn't obey the return type you have ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you, though the issue is not how to work around it, but that Typescript erroneously infers the return type of the function.
Also, pressed the wrong button.