vite TS:Cannot find module './App.vue' or its corresponding type declarations.

155 阅读1分钟

原因:ts只支持模块的导入导出, 无法识别.vue 类型的文件,所以需要用通配符让ts把他们当做模块。

在.d.ts文件里加入以下代码对## 非ts/js文件模块进行类型扩充

js

declare module "*.vue" {
    import { DefineComponent } from "vue"
    const component: DefineComponent<{}, {}, any>
    export default component
}

image.png