microsoft / microsoft/TypeScript
False positive for "Unreachable code detected" for code following `switch`/`case` with `allowUnreachableCode: false`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 Search Terms
"false positive allowUnreachableCode"
"allowUnreachableCode case statement"
"Unreachable code detected case statement"
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
switch/case
⏯ Playground Link
💻 Code
type Foo = "bar" | "baz"
const fn = (value: Foo): number => {
switch(value) {
case "bar":
return 1;
case "baz":
return 2;
}
return assertNever("nope!");
}
🙁 Actual behavior
return assertNever("nope!");
is highlighted as "Unreachable code detected". The docs, however, state:
This does not affect errors on the basis of code which appears to be unreachable due to type analysis.
🙂 Expected behavior
No error. This should be the same as the other case form, the if form, and various similar constructs where even though it's allegedly exhaustive, that's just based off of type information (I would like to have a runtime assertion in this case).
Additional information about the issue
Possibly related to: https://github.com/microsoft/TypeScript/issues/18882
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 und vergleiche das switch/case-Beispiel mit den anderen im Bericht beschriebenen case-Formen. Prüfe anschließend das möglicherweise verwandte Issue #18882 und verifiziere dann, dass die Laufzeitassertion nach dem erschöpfenden switch nicht mehr als unerreichbar gemeldet wird, während das bestehende Verhalten für unerreichbaren Code erhalten bleibt.
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
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100