src / window.d.ts
declare namespace NodeJS {
interface Global {
window: {
location: {};
};
}
}
在我的源代码中,我正在尝试访问global.window.location
。我收到一个错误Property 'window' does not exist on type Global
。
我不知道打字稿编译器是否正在使用我的window.d.ts
?如何告诉编译器使用我的自定义类型?
将此文件路径添加到files
的tsconfig.json
数组中,这样TS就会熟悉它,并扩展真实的Window对象。
顺便说一句,为了将属性添加到全局Window对象:
declare global {
interface Window {
location: {};
}
}