18 Jan 2022   javascript


In this example, we need to put placeholder values on global.window to allow us to use Ruby on Rails’ ActionCable websocket framework where no window exists:

// Fix to prevent crash from ActionCable
global.window.removeEventListener = () => {};
global.window.addEventListener = () => {};

But we need to add a type:

declare global {
	var window: {
		addEventListener(): void;
		removeEventListener(): void;
	};
}
🍄