lyt-Top / vue-next-admin

🎉🎉🔥基于vue3.x 、Typescript、vite、Element plus等,适配手机、平板、pc 的后台开源免费模板库(vue2.x请切换vue-prev-admin分支)
MIT License
1.97k stars 338 forks source link

fix: eslint error of .ts extension alert #2

Closed hom closed 3 years ago

hom commented 3 years ago

使用 VSCode 打开项目的时候,Eslint 的插件会提示 .ts 文件后缀名的错误:

An import path cannot end with a '.ts' extension. Consider importing '/@/i18n/index.js' instead.ts(2691)

该提示建议以 .js来代替 .ts文件后缀名,但是基于 Typescript 的项目中 .js文件是在编译之后产生的,所以我们这里可以省略掉 .ts 的文件后缀名,让 Typescript 引擎来自动处理文件的后缀名。

在打开 src/router/index.ts文件的时候,会提示报错 .vue后缀

Cannot find module '/@/views/layout/index.vue' or its corresponding type declarations.ts(2307)

解决办法:在 src目录中添加了 shims-vue.d.ts文件

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