Skip to content

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

Closed
@besfahbod

Description

@besfahbod

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions