globalThisAliases
Reports using window, self, or global instead of globalThis.
✅ This rule is included in the ts stylisticStrict presets.
This rule enforces the use of globalThis over environment-specific global object aliases like window, self, and global.
globalThis is the standard way to access the global object across all JavaScript environments.
Using window, self, or global ties your code to specific environments (browser, web worker, or Node.js).
Examples
Section titled “Examples”const value = window.localStorage;window.addEventListener("load", handler);const ref = self;const value = globalThis.localStorage;globalThis.addEventListener("load", handler);const ref = globalThis;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you are targeting a specific environment and want to make that explicit in your code, you might choose to use environment-specific globals.
Additionally, some older environments may not support globalThis, though polyfills are available.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Deno:
no-windowno-window-prefix - ESLint:
unicorn/prefer-global-this - Oxlint:
unicorn/prefer-global-this
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.