[英]Property does not exist on type 'Window & typeof globalThis'. Even though it is defined in definition file
這是global.d.ts
interface Window {
routes: any;
routeMaker: any;
store: any;
searchKey: string;
}
據我了解,任何東西都是global.d.ts
本質上與
declare global {
interface Window {
routes: any;
routeMaker: any;
store: any;
searchKey: string;
}
}
坐在根目錄下的是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
}
include
部分指向定義文件。
但是當我使用定義文件中定義的任何道具時..
window.routeMaker = {};
Property 'routeMaker' does not exist on type 'Window & typeof globalThis'.
這是什么原因造成的? 這是如何解決的?
您需要添加至少一個導入或一個導出才能使 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.