Skip to content
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

prefer-math-min-max: ignore bigint variable #2509

Open
yoursunny opened this issue Dec 12, 2024 · 0 comments
Open

prefer-math-min-max: ignore bigint variable #2509

yoursunny opened this issue Dec 12, 2024 · 0 comments
Labels

Comments

@yoursunny
Copy link

unicorn/prefer-math-min-max is incorrectly reporting variables of bigint type.
Its autofix generates invalid code.

package.json

{
  "private": true,
  "type": "module",
  "packageManager": "[email protected]+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c",
  "dependencies": {
    "typescript": "~5.7.2",
    "xo": "^0.60.0"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "forceConsistentCasingInFileNames": true,
    "lib": [
      "DOM",
      "ES2023"
    ],
    "module": "ES2022",
    "moduleResolution": "Bundler",
    "noEmitOnError": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "strict": true,
    "target": "ES2023"
  },
  "include": [
    "main.ts"
  ],
  "exclude": [
    "**/node_modules"
  ]
}

main.ts

export function f(a: bigint, b = 0n) {
	return a > b ? a : b;
}

Command Line

./node_modules/.bin/xo

Error Message

  main.ts:2:9
  ✖  2:9  Prefer Math.max() to simplify ternary expressions.  unicorn/prefer-math-min-max

  1 error

Autofix Result and TypeScript Error

export function f(a: bigint, b = 0n) {
	return Math.max(a, b);
}
main.ts:2:18 - error TS2345: Argument of type 'bigint' is not assignable to parameter of type 'number'.

2  return Math.max(a, b);
                   ~


Found 1 error in main.ts:2
@yoursunny yoursunny added the bug label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant