microsoft / microsoft/TypeScript

bug: error message says 0n is truthy

Aperta
#60,320 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: check: Control Flow
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

falsey, truthy, bigint, PseudoBigInt, TS Error 2872, TS Error 2873, unnecessary condition, constant condition

🕗 Version & Regression Information
⏯ Playground Link

https://www.typescriptlang.org/play/?target=99&ts=5.7.0-dev.20241022#code/JYMwBAFADAdglGA3mFAoAvkA

💻 Code

0n is falsy.

if (0n) {
  // won't happen
}
🙁 Actual behavior

TS 2872: This kind of expression is always truthy.

🙂 Expected behavior

TS 2873: This kind of expression is always falsy.

Additional information about the issue

I am presuming that this is due to this function, which always reports BigIntLiteral as PredicateSemantics.Always, rather than checking for 0n.

https://github.com/microsoft/TypeScript/blob/c07da583afbfbb68930448b781832c74b3f713e6/src/compiler/checker.ts#L44498-L44532

Looks like this has been present since the always-truthy/always-falsey check was initially created: https://github.com/microsoft/TypeScript/pull/59217/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8R44293

I'd be happy to drop a PR if this is accepted and that's the issue.

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 in src/compiler/checker.ts, nella funzione collegata relativa alla semantica dei predicati, e riproduci il comportamento nel link TypeScript Playground fornito. Verifica che 0n sia classificato come sempre falsy e che la diagnostica cambi da TS 2872 a TS 2873, aggiungendo la copertura usando la struttura di test esistente del compilatore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.