question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return type inference error with async functions and Promise.reject()

See original GitHub issue

TypeScript 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:open
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
zombiecommented, Sep 12, 2018

Thank you, though the issue is not how to work around it, but that Typescript erroneously infers the return type of the function.

0reactions
zombiecommented, Sep 12, 2018

Also, pressed the wrong button.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found