Skip to content

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).

const value = window.localStorage;
window.addEventListener("load", handler);
const ref = self;

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.