microsoft / microsoft/TypeScript
typechecking of return types broken with `try/catch` when `strictNullChecks` and `noImplicitAny` are enabled
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der verlinkten TypeScript Playground-Reproduktion, verwende die gezeigte async function und vergleiche --strict mit --strictNullChecks. Verfolge die Behandlung der try/catch-Zuweisung und des Rückgabetyps durch den Typechecker; abgeschlossen ist die Aufgabe, wenn die strikte Konfiguration meldet, dass val möglicherweise null ist und Promise nicht erfüllen kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 38/100