Description
π Search Terms
falsey, truthy, bigint, PseudoBigInt, TS Error 2872, TS Error 2873, unnecessary condition, constant condition
π Version & Regression Information
- This changed between versions 5.5.4 and 5.6.3,
- Disallow truthiness/nullishness checks on syntax that never varies on itΒ #59217 (playground)
β― 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
.
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.