学习TS+VUE3项目中踩过的坑(一)

192 阅读1分钟

拓展全局变量类型推导

这两个问题在网上找到了完全一样的踩坑经验。 🔗

  1. global.d.ts文件中,定义一个namespace

image.png

Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.

全局作用域的扩充只能直接嵌套在外部模块或环境模块声明中。

需要在文件开头加上export {} 使其变成模块文件

  1. 另一个报错

image.png

意思是 declare 修饰符不能用在一个已存在的模块中。

解决方法有两个:
- 删除 declare 修饰符
- 在tsconfig.json文件中配置skipLibCheck: true ,并添加需要include中添加需要引用的文件

知识点: (1)声明合并(# Declaration Merging) (2)skipLibCheck