Skip to content

[no-unused-vars] False positives with members of exported namespace in .d.ts file #2867

Closed
@andersk

Description

@andersk
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "rules": {
    "@typescript-eslint/no-unused-vars": "error"
  }
}
// foo.d.ts
export namespace Foo {
  const bar: string;
  namespace Baz {
    const quux: string;
  }
}

Expected Result

No error. In a .d.ts file, members of an exported namespace are implicitly exported, unless the namespace contains an explicit braced export {} declaration.

Actual Result

/tmp/test/foo.d.ts
  2:9   error  'bar' is defined but never used   @typescript-eslint/no-unused-vars
  3:13  error  'Baz' is defined but never used   @typescript-eslint/no-unused-vars
  4:11  error  'quux' is defined but never used  @typescript-eslint/no-unused-vars

✖ 3 problems (3 errors, 0 warnings)

Additional Info

Similar to #2456, which was about a different kind of implicit export in .d.ts files, namely interface declarations.

Versions

package version
@typescript-eslint/eslint-plugin 4.9.1
@typescript-eslint/parser 4.9.1
TypeScript 4.1.2
ESLint 7.15.0
node 14.15.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: 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