Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: [no-unused-vars] no is assigned a value but only used as a type error when it has a same name type alias declaration exported #10658

@Dunqing

Description

@Dunqing

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.7.2&fileType=.ts&code=MYewdgzgLgBAgjAvDADAbgFAYKYA8AOIATrFAJ77bxIzmUgBm8aQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQHYHsBaWXWZRAE0IDcBDaVDSfAMxcgBpxtIABAFwCeABxQBjaAEth-QiniTc-APQFipclToN0URNGj5okbgF8QpoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

const A = 0;
export type A = typeof A;

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  {
   "rules": {
    "no-unused-vars": "off",
    "@typescript-eslint/no-unused-vars": "error"
    }
  }
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

Should report an error same as https://typescript-eslint.io/play/#ts=5.7.2&fileType=.ts&code=MYewdgzgLgBAgjAvDADAbgFAagTwA4Cm8SMuhIAZvGkA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQHYHsBaWXWZRAE0IDcBDaVDSfAMxcgBpxtIABAFwCeABxQBjaAEth-QiniTc-APQFipclToN0URNGj5okbgF8QpoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

The difference is type A was not exported, so I suspect it is due to const A and type A having the same name, it was mistakenly assumed that const A had also been exported, so no error was reported.

const A = 0;
++ type A = typeof A;
-- export type A = typeof A; 

Actual Result

No error reported

Additional Info

Related: oxc-project/oxc#8488 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions