microsoft / microsoft/TypeScript
Type guard/Equality narrowing doesn't work on "any"
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
type guard equality narrowing strict equal equality
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I found earlier issues (https://github.com/microsoft/TypeScript/pull/9407 and the PR that added this feature https://github.com/microsoft/TypeScript/pull/9407)
⏯ Playground Link
💻 Code
function bar( arg: any ) {
if ( arg === null ) {
return arg;
}
if ( arg === false ) {
return arg;
}
}
🙁 Actual behavior
arg should be null/false inside the if conditions
🙂 Expected behavior
arg is any
The docs say this should work https://www.typescriptlang.org/docs/handbook/2/narrowing.html
When using unknown instead of any it works perfectly fine. I think adjusting this, so it works for any too, isn't too far fetched.
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
Riproduci il comportamento di narrowing nel TypeScript Playground collegato e confrontalo con il comportamento documentato per unknown. Traccia il percorso del type-checker per l’equality narrowing di any, quindi aggiungi una copertura di regressione che mostri che null e false vengono ristretti come previsto ed esegui i test rilevanti del compilatore.
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