下载typeScript
在package.json里加入typeScript
添加类型声明文件
axios.d.ts
import * as axios from 'axios';
declare module 'axios' {
interface AxiosInstance {
(config: AxiosRequestConfig): Promise<any>;
}
}
env.d.ts
/// <reference types="vite/client" />
declare module "*.vue" {
import type {
DefineComponent } from "vue";
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{
}, {
}, any>;
export default component;
}
//环境变量 TypeScript的智能提示
interface ImportMetaEnv {
VITE_APP_TITLE: string;
VITE_APP_PORT: string;
VITE_APP_BASE_API: string;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}
vue-shim.d.ts
declare module "*.vue" {
import Vue from "vue";
export default Vue;
}
auto-imports.d.ts
// Generated by 'unplugin-auto-import'