-
报错“Window & typeof globalThis”上不存在属性“nextLoading”、
-
代码环境:vue3、ts
阮一峰讲解 -
declarets 用法告诉编译器某个类型是存在的
下面的例子是脚本使用浏览器全局对象document。declare var document; document.title = "Hello";
上面示例中,declare 告诉编译器,变量document的类型是外部定义的(具体定义在 TypeScript 内置文件lib.d.ts)
如果 TypeScript 没有找到document的外部定义,这里就会假定它的类型是any。
注意,declare 关键字只用来给出类型描述,是纯的类型代码,不允许设置变量的初始值,即不能涉及值。 -
解决:针对报错
-报错“Window & typeof globalThis”上不存在属性“nextLoading”、
,意思是nextLoading属性没在window上
解决思路,在shim.d.ts
(在最外层根目录上)文件里添加如下代码// shim.d.ts // 记得要加declare declare interface Window { nextLoading: boolean; }
然后在
tsconfig.json
文件里添加代码如下{ "compilerOptions": { "include": [ "./shim.d.ts" // 添加这一行,因为是在最外层注意写相对路径 ], }
ts- declare关键词及vue3报错“Window & typeof globalThis”上不存在属性“nextLoading”、`
于 2024-11-22 16:06:58 首次发布