Skip to content

Rule proposal: prefer declare var for global declarations #2594

@ark120202

Description

@ark120202

Using block-scoped declare const and declare let in global context has a potentially unwanted effect - they can be accessed using unqualified access, but not using globalThis. When this behavior have been implemented in TypeScript (microsoft/TypeScript#30510) all declarations in standard lib files have been changed to declare var, so I believe it's something that generally can be recommended for external declarations too.

// Invalid
declare const foo: string;
// Invalid
export {}
declare global {
	const foo: string;
}
// Valid
export {}
declare const foo: string;

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: 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