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
const value: any
value
=
const window: any
window
.
any
localStorage
;
const window: any
window
.
any
addEventListener
("load",
const handler: any
handler
);
const
const ref: any
ref
=
const self: any
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 ❤️‍🔥 around the world by the Flint team and contributors.