microsoft / microsoft/TypeScript
Reachability analysis of `never` for `yield*` is unchecked
@rbuckton ci sta già lavorando.
Dal 6/6/2024.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 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().
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.