简体   繁体   中英

ESLint throws `no-redeclare` error for global variable with a single declaration

I have defined a writable global variable, AS , in.eslintrc.

AS is only declared once in the codebase.

ESLint is throwing the following no-redeclare error for the single declaration of the global variable:

Error - 'AS' is already defined as a built-in global variable. (no-redeclare)

Why is ESLint throwing a no-redeclare error when the variable is only declared once?

Is there a way to disable this automatically instead of manually disabling the line in the source file?

As I understand, after you defined AS in ESLint as a global variable it considers it already defined so when it encounters var AS =... or function AS() {} in your code it complains about this with no-redeclare

The solution (workaround) I found to this problem - in a browser environment - was to declare the variable (in my case it was a function) attached to the window object.

window.AS = ...

That will not be considered a re-declaration by ESLint v8.21.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM