拓展全局变量类型推导
这两个问题在网上找到了完全一样的踩坑经验。 🔗
- 在
global.d.ts文件中,定义一个namespace
Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.
全局作用域的扩充只能直接嵌套在外部模块或环境模块声明中。
需要在文件开头加上export {} 使其变成模块文件
- 另一个报错
意思是 declare 修饰符不能用在一个已存在的模块中。
解决方法有两个:
- 删除 declare 修饰符
- 在tsconfig.json文件中配置skipLibCheck: true ,并添加需要include中添加需要引用的文件