Skip to content

Bug: [no-unnecessary-condition] should not say that falsey bigint is truthy #10197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
kirkwaiblinger opened this issue Oct 22, 2024 · 1 comment · Fixed by #10205
Closed
4 tasks done

Bug: [no-unnecessary-condition] should not say that falsey bigint is truthy #10197

kirkwaiblinger opened this issue Oct 22, 2024 · 1 comment · Fixed by #10205
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@kirkwaiblinger
Copy link
Member

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.6.3&fileType=.tsx&code=CYUwxgNghgTiAEYD2A7AzgF3gMyhNIAngEICWA5gJIoYBc8ADCgNwBQp28AFLvkWVRoBKeAG9WAXyA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0yHJgBNK%2BSpPRQA7iKaRwYAL4hNQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

declare const falseyBigInt: 0n;
if (falseyBigInt) {
}

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-unnecessary-condition": "warn"
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

Unnecessary conditional, value is always falsy.

Actual Result

Unnecessary conditional, value is always truthy.

Additional Info

This is a bug with this line.

The .value field returns a PseudoBigInt object that looks like { negative?: boolean, base10Value: string }, rather than a bigint itself (for legacy TS support reasons). So checking for truthiness is incorrect; we need to convert to a real bigint.

@kirkwaiblinger kirkwaiblinger added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Oct 22, 2024
@kirkwaiblinger
Copy link
Member Author

Funny enough, TS itself has the same bug, but for completely different root cause: microsoft/TypeScript#60320.

*sigh* guess no one gives bigints much love 😆

@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Oct 22, 2024
@kirkwaiblinger kirkwaiblinger added the good first issue Good for newcomers label Oct 24, 2024
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Nov 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants