[英]Property does not exist on type 'Window & typeof globalThis'. Even though it is defined in definition file
This is global.d.ts
这是
global.d.ts
interface Window {
routes: any;
routeMaker: any;
store: any;
searchKey: string;
}
As far as I understand, anything is global.d.ts
is essentially the same as据我了解,任何东西都是
global.d.ts
本质上与
declare global {
interface Window {
routes: any;
routeMaker: any;
store: any;
searchKey: string;
}
}
Sitting in root, is the tsconfig.json
in which I have pointed to the defination files..坐在根目录下的是
tsconfig.json
我在其中指出了定义文件。
{
"compilerOptions": {
"target": "es6",
"declaration": false,
"emitDecoratorMetadata": true,
"baseUrl": ".",
"experimentalDecorators": true,
"lib": ["es6", "dom", "webworker"],
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"jsx": "react",
"typeRoots": ["node_modules/@types", "types"],
"types": ["node", "webpack-env"],
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"exclude": ["**/*.spec.js", "node_modules", "vendor", "public"],
"include": [
"types/global.d.ts",
"**/*.d.ts",
"app/client/src",
"app/*.ts"
],
"compileOnSave": false
}
The include
section points the definition file. include
部分指向定义文件。
But when I use any props defined in the definition file..但是当我使用定义文件中定义的任何道具时..
window.routeMaker = {};
Property 'routeMaker' does not exist on type 'Window & typeof globalThis'.
What causes this?这是什么原因造成的? And how is this fixed?
这是如何解决的?
You need to add at least one import or one export in order to make global.d.ts an external module to have a global scope effect, so in your case you can do the following:您需要添加至少一个导入或一个导出才能使 global.d.ts 成为具有全局 scope 效果的外部模块,因此在您的情况下,您可以执行以下操作:
declare global {
interface Window {
routes: any;
routeMaker: any;
store: any;
searchKey: string;
}
}
export {};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.