简体   繁体   English

类型“Window & typeof globalThis”上不存在属性。 即使它是在定义文件中定义的

[英]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.

相关问题 类型 Window 和 typeof globalThis 上不存在属性 - Property does not exist on type Window & typeof globalThis Angular:属性“xxx”在类型“Window & typeof globalThis”上不存在 - Angular: Property 'xxx' does not exist on type 'Window & typeof globalThis' 属性 'MktoForms2' 在类型 'Window & typeof globalThis' 上不存在 - Property 'MktoForms2' does not exist on type 'Window & typeof globalThis' React中的'Window&typeof globalThis'类型上不存在'属性'ethereum''错误 - `Property 'ethereum' does not exist on type 'Window & typeof globalThis'` error in React 类型“Window & typeof globalThis”上不存在属性“showSaveFilePicker” - Property 'showSaveFilePicker' does not exist on type 'Window & typeof globalThis' 错误消息:“类型 'Window & typeof globalThis' 上不存在属性 'EyeDropper'。” - Error message: "Property 'EyeDropper' does not exist on type 'Window & typeof globalThis'." 属性 '_env_' 不存在于类型 'Window & typeof globalThis - React / Typescript 错误 - property '_env_' does not exist on type 'Window & typeof globalThis - React / Typescript ERROR Typescript Node JS - 类型“Global & typeof globalThis”上不存在“属性” - Typescript Node JS - `Property does not exist on type 'Global & typeof globalThis'` TypeScript:“Window & typeof globalThis”上不存在属性“X”:使用“declare global”的建议解决方案给了我错误 - TypeScript: Property 'X' does not exist on 'Window & typeof globalThis': suggested solution using 'declare global' gives me error 尽管使用 global.d.ts 修改全局,但类型“全局和 typeof globalThis”上不存在属性“用户” - Property 'users' does not exist on type 'Global & typeof globalThis' although modifying global with global.d.ts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM