I would like to extend the window
object with a new property. This can be achieved by adding the following code:
// global.d.ts
import { IConfig } from './src/models';
export {};
declare global {
interface Window {
_env: IConfig;
}
}
However, when attempting to access this new property in a different file, an error is triggered:
// src/util.ts
// Property '_env' does not exist on type 'Window & typeof globalThis'.
export const URL = `https://example.com/${window._env.path}`;
Interestingly, when these code snippets are combined into the same file, no errors occur. Is there a way to keep them separate and still avoid errors?
My TypeScript version is 4.1.2.