AssetManager.UniApp/types/shims.d.ts
claw_bot fa2fa98985 feat: TypeScript 迁移完成
- 新增 tsconfig.json 配置
- 新增 types/ 目录(7个类型定义文件,与后端 DTO 对齐)
- 迁移 vite.config.js → vite.config.ts
- 迁移 main.js → main.ts
- 迁移 utils/api.js → utils/api.ts(泛型化请求封装)
- 迁移 utils/currency.js → utils/currency.ts
- 迁移 6 个 Vue 页面组件(添加 lang="ts" 和类型注解)
- 新增 TYPESCRIPT_MIGRATION.md 迁移计划文档
- 更新 todo.md 进度

收益:完整类型提示、编译时错误检查、重构安全性提升
2026-03-24 05:53:29 +00:00

84 lines
2.4 KiB
TypeScript

/**
* 模块类型声明
*/
// uni-app 全局声明
declare const uni: {
login(options: { provider: string; success: (res: any) => void; fail: (err: any) => void }): void;
request(options: { url: string; method?: string; data?: any; header?: any; timeout?: number; success: (res: any) => void; fail: (err: any) => void }): void;
showLoading(options: { title: string; mask?: boolean }): void;
hideLoading(): void;
showToast(options: { title: string; icon?: string; duration?: number }): void;
getStorageSync(key: string): any;
setStorageSync(key: string, value: any): void;
removeStorageSync(key: string): void;
};
// Vite import.meta.env
interface ImportMetaEnv {
VITE_API_BASE_URL?: string;
[key: string]: any;
}
interface ImportMeta {
env: ImportMetaEnv;
}
// Vue 模块声明
declare module 'vue' {
import type { App, DefineComponent, ComponentPublicInstance } from '@vue/runtime-core'
export function createSSRApp(component: any): App
export function ref<T>(value: T): { value: T }
export function reactive<T>(obj: T): T
export function computed<T>(fn: () => T): { value: T }
export function watch(source: any, cb: any, options?: any): void
export function onMounted(fn: () => void): void
export function onUnmounted(fn: () => void): void
export function nextTick(fn?: () => void): Promise<void>
export function defineComponent(component: any): DefineComponent
export function provide(key: any, value: any): void
export function inject(key: any): any
export interface App {
config: {
globalProperties: Record<string, any>
}
use(plugin: any, ...options: any[]): App
component(name: string, component: any): App
mount(rootContainer: any): ComponentPublicInstance
}
export interface Plugin {
install(app: App, ...options: any[]): void
}
export type { DefineComponent, ComponentPublicInstance }
}
// Vue 单文件组件声明
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
// uview-plus 模块声明
declare module '@/uni_modules/uview-plus' {
import type { Plugin } from 'vue'
const uviewPlus: Plugin
export default uviewPlus
}
// vite 模块声明
declare module 'vite' {
export function defineConfig(config: any): any;
}
// @dcloudio/vite-plugin-uni
declare module '@dcloudio/vite-plugin-uni' {
import type { Plugin } from 'vite'
function uni(): Plugin
export default uni
}