Skip to content

Rule proposal: prefer declare var for global declarations #2594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ark120202 opened this issue Sep 23, 2020 · 2 comments
Open

Rule proposal: prefer declare var for global declarations #2594

ark120202 opened this issue Sep 23, 2020 · 2 comments
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@ark120202
Copy link

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;
@ark120202 ark120202 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Sep 23, 2020
@bradzacher bradzacher added enhancement: new plugin rule New rule request for eslint-plugin and removed triage Waiting for team members to take a look labels Sep 24, 2020
@JoshuaKGoldberg JoshuaKGoldberg added the accepting prs Go ahead, send a pull request that resolves this issue label Oct 25, 2021
@kirkwaiblinger
Copy link
Member

Note that the "accepting prs" should be taken with a grain of salt here while #7941 is being discussed

@kirkwaiblinger
Copy link
Member

reopening based on eslint/eslint#19714 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

4 participants