microsoft / microsoft/TypeScript
TypeScript does not recognize unreachable code after a method returning never is called outside of its defining scope
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.89.1
- OS Version: All
To Reproduce:
class SimpleThrower {
public throwError(): never {
throw new Error('');
}
public doSomething(): string {
this.throwError(); // Directly call the never-returning function
return 'Success'; // TypeScript recognizes that this line is unreachable
}
}
() => {
const example = new SimpleThrower();
console.log(example.doSomething()); // This will throw an error
example.throwError(); // Throws an error and stops execution
console.log('foobar'); // TypeScript does not recognize that this line is unreachable
}
Expected behavior:
TypeScript should recognize that the line console.log('foobar'); is unreachable after example.throwError(); is called, similar to how it recognizes the unreachable code within the doSomething method.
Actual behavior:
TypeScript does not mark the line console.log('foobar'); as unreachable after the example.throwError(); call in the global scope or within a different function scope.
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 con il Playground Link fornito e confronta il modo in cui il codice irraggiungibile viene riconosciuto all'interno di doSomething dopo this.throwError() con il comportamento dopo example.throwError() nella funzione esterna. Traccia il punto di ingresso dell'analisi del flusso di controllo di TypeScript responsabile delle chiamate ai metodi che restituiscono never; il lavoro è completato quando console.log('foobar') viene contrassegnato come irraggiungibile nel secondo caso senza regredire nel comportamento esistente dei metodi.
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à
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 42/100