From d29e5ba0627438e8b45b766ff31755aacb7ae18b Mon Sep 17 00:00:00 2001 From: pany <939630029@qq.com> Date: Thu, 21 Nov 2024 19:52:07 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=85=A8=E5=B1=80=20?= =?UTF-8?q?ts=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tsconfig.json | 11 ++++++++++- types/env.d.ts | 2 +- types/global-components.d.ts | 6 +++--- types/global-directives.d.ts | 11 +++++++++++ types/shims-vue.d.ts | 4 ---- types/vue-router.d.ts | 2 ++ 6 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 types/global-directives.d.ts delete mode 100644 types/shims-vue.d.ts diff --git a/tsconfig.json b/tsconfig.json index dcc7d466..6f09e6c7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,7 @@ +// https://www.typescriptlang.org/tsconfig // https://cn.vuejs.org/guide/typescript/overview#configuring-tsconfig-json // https://cn.vite.dev/guide/features#typescript-compiler-options + { "compilerOptions": { "target": "esnext", @@ -27,6 +29,13 @@ "isolatedModules": true, "skipLibCheck": true }, - // 编译器默认排除的编译文件 + // 需要被编译的文件列表 + "include": [ + "**/*.ts", + "**/*.tsx", + "**/*.vue", + "**/*.d.ts" + ], + // 从编译中排除的文件列表 "exclude": ["node_modules", "dist"] } diff --git a/types/env.d.ts b/types/env.d.ts index 78566444..4b07d10f 100644 --- a/types/env.d.ts +++ b/types/env.d.ts @@ -1,7 +1,7 @@ /** 声明 vite 环境变量的类型(如果未声明则默认是 any) */ interface ImportMetaEnv { readonly VITE_APP_TITLE: string - readonly VITE_BASE_API: string + readonly VITE_BASE_URL: string readonly VITE_ROUTER_HISTORY: "hash" | "html5" readonly VITE_PUBLIC_PATH: string } diff --git a/types/global-components.d.ts b/types/global-components.d.ts index 9dc22962..0832cc82 100644 --- a/types/global-components.d.ts +++ b/types/global-components.d.ts @@ -1,10 +1,10 @@ import type SvgIcon from "@/components/SvgIcon/index.vue" -/** 由 app.component 全局注册的组件需要在这里声明 TS 类型才能获得 Volar 插件提供的类型提示) */ +export {} + +// 由 app.component 全局注册的组件需要在这里声明 TS 类型才能获得 Volar 插件提供的类型提示) declare module "vue" { export interface GlobalComponents { SvgIcon: typeof SvgIcon } } - -export {} diff --git a/types/global-directives.d.ts b/types/global-directives.d.ts new file mode 100644 index 00000000..0eb4e2db --- /dev/null +++ b/types/global-directives.d.ts @@ -0,0 +1,11 @@ +import type { Directive } from "vue" + +export {} + +// 由 app.directive 全局注册的自定义指令需要在这里声明 TS 类型才能获得类型提示 +declare module "vue" { + export interface ComponentCustomProperties { + vLoading: Directive + vPermission: Directive + } +} diff --git a/types/shims-vue.d.ts b/types/shims-vue.d.ts deleted file mode 100644 index 4d4e42f9..00000000 --- a/types/shims-vue.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module "*.scss" { - const scss: Record - export default scss -} diff --git a/types/vue-router.d.ts b/types/vue-router.d.ts index bab831fd..83cc1bdf 100644 --- a/types/vue-router.d.ts +++ b/types/vue-router.d.ts @@ -1,5 +1,7 @@ import "vue-router" +export {} + declare module "vue-router" { interface RouteMeta { /**