microsoft / microsoft/TypeScript
`unknown && false` is too loosely typed
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
The following code should type-check: https://www.typescriptlang.org/play?#code/FAFwngDgpgBAYgQwDYGcwwLwwHYFclIwA+Mu2AJlAGYCW2U5xMVyKsJeAtgEZQBOTAAzYmAIlFMAEgBUAsgBkAggQDCAewJQAxiBprswYFTI69IqmrUAKAB4AuUtgDW2NQHdsASgeJU6AN7AMMEwfFAguHwiNjAAZLHMrFDAAL7AQA
🔎 Search Terms
unknown falsy false and &&
🕗 Version & Regression Information
Please keep and fill in the line that best applies:
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about unknown values and &&
⏯ Playground Link
Playground link with relevant code
💻 Code
type Falsy = null | undefined | false | number | 0n | "" | HTMLAllCollection
function foo(x: unknown): Falsy {
return x && false
}
🙁 Actual behavior
Fails to type-check
🙂 Expected behavior
Should type-check
This would be improved further if:
- NaN was its own type, so
Falsycould be more specific thannumber. (#28682) Falsy/Truthywere built in types.HTMLAllCollectionvariant could be omitted as a legacy value sincedocument.allis deprecated and it's otherwise the case that objects are not falsy.
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 collegato di TypeScript Playground e riproduci il problema di type-checking segnalato per la funzione foo. Traccia la gestione di unknown, && e del tipo di ritorno Falsy da parte del compilatore; il lavoro è completato quando l'esempio supera il type-checking come previsto.
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
- Specificata chiaramente
- Idoneità per principianti
- 42/100