microsoft / microsoft/TypeScript
Checking if Enum | falsely in if condition if value of Enum might be zero
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Suggestion
🔍 Search Terms
checker, enum, undefined, dx
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
Check if a value has enum | falsely types, and one member of the enum is zero. And the value In top level of If/while/etc's conditions.
It's a common bug case. Even after condition, CFA could strip the zero value. But If we does not use the enum value, we will never find it out.
📃 Motivating Example
enum E {
Foo,
Bar
}
function foo (v: E | undefined) {
if (!v) { // Should be suggestion or error?
throw new Error("Hoops")
}
console.log("Acceptable") // But without E.foo
}
💻 Use Cases
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 l’esempio motivante E | undefined e rivedi il comportamento del checker per il narrowing basato sulla truthiness nelle condizioni if. Determina se il risultato debba essere un suggerimento o un errore, quindi definisci test che coprano un membro dell’enum con valore zero e il tipo ristretto; il lavoro è completo quando il comportamento diagnostico previsto è specificato e coperto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100