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: Storage
value
=
var window: Window & typeof globalThis

The window property of a Window object points to the window object itself.

MDN Reference

window
.
localStorage: Storage
localStorage
;
var window: Window & typeof globalThis

The window property of a Window object points to the window object itself.

MDN Reference

window
.
addEventListener<"load">(type: "load", listener: (this: Window, ev: Event) => any, options?: boolean | AddEventListenerOptions): void (+1 overload)

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

addEventListener
("load",
const handler: EventListener
handler
);
const
const ref: Window & typeof globalThis
ref
=
var self: Window & typeof globalThis

The Window.self read-only property returns the window itself, as a WindowProxy.

MDN Reference

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.