Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[no-shadow] declaring a global causes no-shadow to error #2654

Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestgood first issueGood for newcomerslocked 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
@salemhilal

Description

@salemhilal

Hey, I think I found what's either a bug or a confusing way that globals and ambient types are handled (potentially similarly to theno-undef issuementioned in the FAQs).

I'm currently migrating a large codebase to use TypeScript. We have a globalhas() function that we use to determine what environment we're in. It's handled by our build system, and is set as a read-only global in our existing ESLint config.

When I try and declare an ambient type for this global, I've noticed that@typescript-eslint/no-shadow thinks that I'm shadowing it. Removingglobals: { has: false } from the config fixes this problem. Is this expected behavior?

Thanks in advance, and sorry if I'm overlooking something.

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

Repro

I set up a fresh project by running the following in an empty directory:

yarn init -yyarn add -D eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin

I then added these two files

// .eslintrc.jsmodule.exports={root:true,parser:'@typescript-eslint/parser',plugins:['@typescript-eslint',],extends:['eslint:recommended','plugin:@typescript-eslint/recommended',],globals:{has:false,},rules:{"no-shadow":"off","@typescript-eslint/no-shadow":["error",{builtinGlobals:true}],}};
// index.d.tsdeclareconsthas:(environment:"dev"|"prod"|"test")=>boolean;

Expected Result

I'd expectyarn eslint index.d.ts to not error.

Actual Result

It logged the following error:

 1:15  error  'has' is already declared in the upper scope  @typescript-eslint/no-shadow

Versions

packageversion
@typescript-eslint/eslint-plugin4.4.0
@typescript-eslint/parser4.4.0
TypeScript4.0.3
ESLint7.10.0
node12.15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestgood first issueGood for newcomerslocked 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

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp