microsoft / microsoft/TypeScript
False positive for "Unreachable code detected" for code following `switch`/`case` with `allowUnreachableCode: false`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 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
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 e confronta l’esempio di switch/case con le altre forme di case descritte nel report. Esamina il possibile issue correlato #18882, quindi verifica che l’asserzione a runtime dopo lo switch esaustivo non venga più segnalata come irraggiungibile, mentre il comportamento esistente per il codice irraggiungibile rimane invariato.
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
- Abbastanza chiara
- Idoneità per principianti
- 35/100