microsoft / microsoft/TypeScript
typechecking of return types broken with `try/catch` when `strictNullChecks` and `noImplicitAny` are enabled
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
🔎 Search Terms
try/catch, exception handling, strict mode
🕗 Version & Regression Information
Broken in 4.3.5, still broken in nightly
⏯ Playground Link
Playground link with strict mode
Disable --noImplicitAny and --strict (but leave --strictNullChecks) and typechecker will correctly note that val may have type null
💻 Code
declare function bar(): any;
async function foo(): Promise<string> {
let val = null;
try {
val = bar();
} catch (e) {}
return val;
}
🙁 Actual behavior
Compile with --strict and observe no errors
Compile simply with --strictNullChecks and typechecker will correctly note that val may have type null and does not conform to the return type
🙂 Expected behavior
typechecker should correctly determine that val can have type null and does not conform to the return type
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 la riproduzione collegata in TypeScript Playground, usando la async function mostrata e confrontando --strict con --strictNullChecks. Traccia la gestione da parte del typechecker dell’assegnazione del try/catch e del tipo restituito; il lavoro è completato quando la configurazione strict segnala che val può essere null e non può soddisfare Promise.
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
- 38/100