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

Base rule extension: no-var configuration for declarations #7941

Closed as not planned
Labels
enhancement: new base rule extensionNew base rule extension required to handle a TS specific caseexternalThis issue is with another package, not typescript-eslint itselfpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@DanKaplanSES

Description

@DanKaplanSES

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the base rule

https://eslint.org/docs/latest/rules/no-var

Description

Typescript global declarations are more subtle than I ever expected. For a better understanding, I recommend these SO answers:

Here are some key takeaways. If you want to add properties toglobalThis:

  1. When the typescript file has noimport orexport keyword (i.e., it's a script, not a module), it is done like so:declare var age: number.
  2. When the typescript file does haveimport orexport, you write this instead:
    // an import / export linedeclare global{varage:number;}

Ifconst orlet is used instead ofvar,globalThis.age = 18 would error in both scenarios. So if the intention is to declareglobalThis.age, it isnecessary to use thevar keyword: usingconst orlet would be a mistake. When enabled, the baseno-var rule indiscriminately marks allvar usage as wrong, but in this case, it is required.

Fail

/*eslint no-var: "error"*/export{}varx="y";varCONFIG={};

Pass

export{}declare global{varage:number;}

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: new base rule extensionNew base rule extension required to handle a TS specific caseexternalThis issue is with another package, not typescript-eslint itselfpackage: 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