Skip to content

Bug: [no-unnecessary-type-conversion] Double tilde operator does not change type, but change value #11569

@pedro00dk

Description

@pedro00dk

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.9.2&fileType=.tsx&code=MYewdgzgLgBAHjAvDAjAOgKwChSVgTyRgD9i4dwIQAbAUzWpAHMAKAbzgBoZ8BfAShgB6ITAAOAJwCWYKBBht4ALlSZu%2BFSl5YgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWmQ5MAbomjJKM9FAXQO0SODABfELqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

const x = 1.5
const y = ~~x
console.log({x, y}) // prints { x: 1.5, y: 1 }

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unnecessary-type-conversion": "error"
  }
};

tsconfig

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

Expected Result

There should be no lint error.

Actual Result

Rule complains about usage of double tilde operator.

Additional Info

The no-unecessary-type-conversion rule should not be applied when using a a tilde operator twice even if the operand type is already a number.
A double tilde operator will not perform just a type conversion, but will also floor decimal numbers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already existspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions