Vuestic 和 Typescript 集成
Vuestic and Typescript Integration
我是 Vue 和 Vuestic 的新手,我想知道是否可以将 Typescript 集成到 Vuestic 项目中。如果可能,我该如何完成?
使用 Vuestic CLI 创建了一个新项目并且 运行 它没有任何问题:
vuestic testproj
npm install && npm run serve
然后我尝试使用 Vue CLI 将 Typescript 添加到项目中:
vue add typescript
? Use class-style component syntax? Yes
? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpil ing JSX)? Yes
? Convert all .js files to .ts? Yes
? Allow .js files to be compiled? Yes
? Skip type checking of all declaration files (recommended for apps)? Yes
我遇到了数百个与这些类似的错误:
Cannot find module './App' or its corresponding type declarations.
Property 'AD' does not exist on type '{}'
Cannot find module '../components/admin/AppLayout' or its corresponding type declarations.
...
知道如何添加 Typescript 并解决这些问题吗?
对于找不到模块 ./App,以正确的文件结尾结束导入很重要。例如./App.vue。
Vue 打字稿项目还需要一个 shims-vue.d.ts 文件,您可以将其放在 src 目录中。它应该包含:
declare module "*.vue" {
import type { DefineComponent } from "vue";
const component: DefineComponent<{}, {}, any>;
export default component;
}
我不建议使用自动将所有 js 文件转换为 ts 文件。手动执行此操作,这样可以更轻松地查看创建错误的位置。
我是 Vue 和 Vuestic 的新手,我想知道是否可以将 Typescript 集成到 Vuestic 项目中。如果可能,我该如何完成?
使用 Vuestic CLI 创建了一个新项目并且 运行 它没有任何问题:
vuestic testproj
npm install && npm run serve
然后我尝试使用 Vue CLI 将 Typescript 添加到项目中:
vue add typescript
? Use class-style component syntax? Yes ? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpil ing JSX)? Yes ? Convert all .js files to .ts? Yes ? Allow .js files to be compiled? Yes ? Skip type checking of all declaration files (recommended for apps)? Yes
我遇到了数百个与这些类似的错误:
Cannot find module './App' or its corresponding type declarations.
Property 'AD' does not exist on type '{}'
Cannot find module '../components/admin/AppLayout' or its corresponding type declarations.
...
知道如何添加 Typescript 并解决这些问题吗?
对于找不到模块 ./App,以正确的文件结尾结束导入很重要。例如./App.vue。 Vue 打字稿项目还需要一个 shims-vue.d.ts 文件,您可以将其放在 src 目录中。它应该包含:
declare module "*.vue" {
import type { DefineComponent } from "vue";
const component: DefineComponent<{}, {}, any>;
export default component;
}
我不建议使用自动将所有 js 文件转换为 ts 文件。手动执行此操作,这样可以更轻松地查看创建错误的位置。