对非ts/js文件模块进行类型扩充
ts只支持模块的导入导出, 但是有些时候你可能需要引入css/html等文件, 这时候就需要用通配符让ts把他们当做模块, 下面是对".vue"文件的导入支持(来自vue官方):
找不到 .vue 的声明文件,实际上就是 TS 无法识别 .vue 类型的文件。
引入.vue文件提示“Could not find a declaration file for module ‘xxx.vue’…”
有时候在开发过程中只是提示有错,不影响项目运行,但在打包时会报错,导致无法打包。
在src文件目录下(也就是你开发代码所在的文件夹)添加 shims-vue.d.ts 文件,内容为
// global.d.ts
declare module '*.vue' {
import { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}