microsoft / microsoft/TypeScript
Reachability analysis of `never` for `yield*` is unchecked
@rbuckton is already working on this.
Since Jun 6, 2024.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
reachability never
🕗 Version & Regression Information
It's observed in all TS versions.
⏯ Playground Link
💻 Code
function* never(): Generator<unknown,never> {
throw 'never';
}
function* main() {
try {
yield* never();
} finally {
console.log('finally');
}
console.log('not reachable');
}
🙁 Actual behavior
No error reported.
🙂 Expected behavior
There should be an error Unreachable code detected.(7027) at line 11 console.log('not reachable');.
Additional information about the issue
Reachability analysis is working for normal function: https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABGApgNxQJwBQEoBcy6WiA3gFCKJQAWmcA7ogOSoabMDc5AvueaEiwEiALYBDGGDxlK1TAE9ZVKmyx5uVHomBTxAG31KKKxBAQBnOPpQA6fXADm2ZrrAGjzXJsR8q5sCsbeycXMDgoREwUcQgacQAjGy9uPiA
It's broken for Promise and we have another issue tracking that one: https://github.com/microsoft/TypeScript/issues/34955
Generator functions are being used as coroutine in libraries like co.js, Effect.js, redux-saga, Effection, and more. It's common to write a coroutine operator that suspend the thread forever, thus taking function never(): Generator<Instruction, never> signature. It would benefit users if the TypeScript control analysis can infer unreachability after yield* never().
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.