type GlobalState = typeof Window.prototype & { windowExists: boolean } & Record; type DocumentShim = typeof Document.prototype & { windowExists: boolean }; const globalState: GlobalState = (typeof window !== 'undefined') ? window : { addEventListener: () => { }, removeEventListener: () => { }, matchMedia: () => ({}), getComputedStyle: () => ({}), fetch, } as any; const documentWrap: DocumentShim = (typeof window !== 'undefined') ? document : { querySelector: () => null, } as any; if (typeof window !== 'undefined') { globalState.windowExists = true; documentWrap.windowExists = true; } else { globalState.windowExists = false; documentWrap.windowExists = false; } export { documentWrap, globalState };