microsoft / microsoft/TypeScript

`unknown && false` is too loosely typed

Aperta
#53,352 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
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 Falsy could be more specific than number. (#28682)
  • Falsy/Truthy were built in types.
  • HTMLAllCollection variant could be omitted as a legacy value since document.all is deprecated and it's otherwise the case that objects are not falsy.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. 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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.