microsoft / microsoft/TypeScript
Why doesn't awaiting a Promise<never> change reachability?
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript Version: 3.7.2
Search Terms:
- "Promise"
await- reachability analysis
- control flow analysis
- definite assignment analysis
Code
(async () => {
let b: string;
let a1 = await Promise.reject(); // returns Promise<never>
b = ""; // Not unreachable?
b.toUpperCase(); // Not unreachable?
})();
Expected behavior:
As a1 is inferred to be never (e.g. behaves like in the non-promised version), I expected the rest of the code to be marked as unreachable aswell:
function returnNever(): never { throw new Error(); }
(async () => {
let b: string;
let a0 = returnNever(); // a0 is never
b = ""; // Unreachable
b.toUpperCase(); // Unreachable
})();
Actual behavior:
The code after the never-returning promise is marked as reachable.
Related Question on StackOverflow: Has more code: https://stackoverflow.com/questions/58732814
Related Issue: https://github.com/microsoft/TypeScript/issues/10973 (although marked as "Working as intended", it was changed later. 3.7.2 behaves like the issue opener expected).
If this is not a bug, what is the background for this behavior?
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.
Direzione di ricerca
Inizia riproducendo l'esempio async fornito e confronta la sua raggiungibilità con l'esempio diretto di returnNever(). Leggi l'analisi di control-flow, reachability e definite-assignment del compilatore relativa a await e Promise; il lavoro è completato quando si determina se il comportamento è intenzionale o si aggiunge un test di regressione mirato per il risultato previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100