Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awaiting on a Promise<never> doesn't make the rest of the block unreachable #49902

Closed
besfahbod opened this issue Jul 14, 2022 · 1 comment
Closed

Comments

@besfahbod
Copy link

Bug Report

🔎 Search Terms

TS2534 await

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I couldn't find any related FAQ entries.

Versions tried on:

  • 4.6.4 (local)
  • Nightly = 4.8.0-dev.20220714) (playground)

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.8.0-dev.20220714#code/GYVwdgxgLglg9mABAWwIYGsCmARTUGr4BOAFAJQBciACkXMjAM6YA8YmAbpkQHyIDeAKEQjERPCCJJa9JpgB04gFaZoJdgHdEAUSJ1SAIgBCcegEIDZMgG5BAX0GDQkWAkQATPASiYAjOSoZBmY2Tm4+IREIBEYoDy8wQjgiILlEAF4UDBwEpNIbYTEJKXj8ROJU5lsHQVRGAE9IRGdoeCRPMsJMACYAmjpg1nYuXgFC6LBY0u9kyswMrKxcTuJyWxFUDVQYOI6ZlIG5aqA

💻 Code

function makeDetonator(): Promise<never> {
    return Promise.reject(new Error("Boom!"));
}

function detonate1(): Promise<never> {
  const detonatorPromise = makeDetonator();
  return detonatorPromise;
}

async function detonate2(): Promise<never> {
  const detonatorPromise = makeDetonator();
  await detonatorPromise;
}

🙁 Actual behavior

detonate1 has no issues, but get the following error for detonate2:

A function returning 'never' cannot have a reachable end point.

🙂 Expected behavior

detonate2 is semantically equivalent to detonate1, and there should be no such error.

It looks like the general rule that's missing is: awaiting on a Promise would make the rest of the block unreachable.

image

@MartinJohns
Copy link
Contributor

Duplicate of #34955. Used search terms: promise never in:title

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants