From a98835e18b441ce9e6e5b035ea9aa08c91f6a101 Mon Sep 17 00:00:00 2001 From: Vben Date: Fri, 26 Mar 2021 22:22:58 +0800 Subject: [PATCH] chore: types --- .../Form/src/components/ApiSelect copy.vue | 127 ------------- src/components/Scrollbar/src/bar.ts | 2 +- .../Table/src/components/editable/index.ts | 2 +- src/components/Table/src/types/table.ts | 2 +- src/directives/ripple/index.ts | 2 +- src/hooks/component/useFormItem.ts | 2 +- src/layouts/page/transition.ts | 2 +- src/router/guard/permissionGuard.ts | 2 +- src/utils/http/axios/types.ts | 2 +- types/global.d.ts | 170 +++++++++--------- types/index.d.ts | 26 +++ types/module.d.ts | 6 + types/tsx.d.ts | 19 -- types/vue-app-env.d.ts | 5 - types/window.d.ts | 8 - 15 files changed, 122 insertions(+), 255 deletions(-) delete mode 100644 src/components/Form/src/components/ApiSelect copy.vue create mode 100644 types/index.d.ts delete mode 100644 types/tsx.d.ts delete mode 100644 types/vue-app-env.d.ts delete mode 100644 types/window.d.ts diff --git a/src/components/Form/src/components/ApiSelect copy.vue b/src/components/Form/src/components/ApiSelect copy.vue deleted file mode 100644 index d4288b323..000000000 --- a/src/components/Form/src/components/ApiSelect copy.vue +++ /dev/null @@ -1,127 +0,0 @@ - - diff --git a/src/components/Scrollbar/src/bar.ts b/src/components/Scrollbar/src/bar.ts index cc988a260..28f804c5e 100644 --- a/src/components/Scrollbar/src/bar.ts +++ b/src/components/Scrollbar/src/bar.ts @@ -28,7 +28,7 @@ export default defineComponent({ const bar = computed(() => { return BAR_MAP[props.vertical ? 'vertical' : 'horizontal']; }); - const barStore = ref({}); + const barStore = ref({}); const cursorDown = ref(null); const clickThumbHandler = (e: any) => { // prevent click event of right button diff --git a/src/components/Table/src/components/editable/index.ts b/src/components/Table/src/components/editable/index.ts index 3785b2d09..00fd81ef3 100644 --- a/src/components/Table/src/components/editable/index.ts +++ b/src/components/Table/src/components/editable/index.ts @@ -41,7 +41,7 @@ export function renderEditCell(column: BasicColumn) { }; } -export type EditRecordRow> = Partial< +export type EditRecordRow = Partial< { onEdit: (editable: boolean, submit?: boolean) => Promise; editable: boolean; diff --git a/src/components/Table/src/types/table.ts b/src/components/Table/src/types/table.ts index c49f71657..7532f8cde 100644 --- a/src/components/Table/src/types/table.ts +++ b/src/components/Table/src/types/table.ts @@ -402,7 +402,7 @@ export interface BasicColumn extends ColumnProps { flag?: 'INDEX' | 'DEFAULT' | 'CHECKBOX' | 'RADIO' | 'ACTION'; customTitle?: VueNode; - slots?: Indexable; + slots?: Recordable; // Whether to hide the column by default, it can be displayed in the column configuration defaultHidden?: boolean; diff --git a/src/directives/ripple/index.ts b/src/directives/ripple/index.ts index 88e188f6d..85a80e8f3 100644 --- a/src/directives/ripple/index.ts +++ b/src/directives/ripple/index.ts @@ -181,7 +181,7 @@ function rippler({ }; } -function setProps(modifiers: Hash, props: Recordable) { +function setProps(modifiers: Recordable, props: Recordable) { modifiers.forEach((item: Recordable) => { if (isNaN(Number(item))) props.event = item; else props.transition = item; diff --git a/src/hooks/component/useFormItem.ts b/src/hooks/component/useFormItem.ts index bb58b7d62..2f5a2a4c6 100644 --- a/src/hooks/component/useFormItem.ts +++ b/src/hooks/component/useFormItem.ts @@ -3,7 +3,7 @@ import { reactive, readonly, computed, getCurrentInstance, watchEffect } from 'v import { isEqual } from 'lodash-es'; -export function useRuleFormItem( +export function useRuleFormItem( props: T, key: keyof T = 'value', changeEvent = 'change' diff --git a/src/layouts/page/transition.ts b/src/layouts/page/transition.ts index 1d22c9aeb..b21f2e2a0 100644 --- a/src/layouts/page/transition.ts +++ b/src/layouts/page/transition.ts @@ -2,7 +2,7 @@ import type { FunctionalComponent } from 'vue'; import type { RouteLocation } from 'vue-router'; export interface DefaultContext { - Component: FunctionalComponent & { type: Indexable }; + Component: FunctionalComponent & { type: Recordable }; route: RouteLocation; } diff --git a/src/router/guard/permissionGuard.ts b/src/router/guard/permissionGuard.ts index 5bd7d19db..88c19b702 100644 --- a/src/router/guard/permissionGuard.ts +++ b/src/router/guard/permissionGuard.ts @@ -38,7 +38,7 @@ export function createPermissionGuard(router: Router) { return; } // redirect login page - const redirectData: { path: string; replace: boolean; query?: Indexable } = { + const redirectData: { path: string; replace: boolean; query?: Recordable } = { path: LOGIN_PATH, replace: true, }; diff --git a/src/utils/http/axios/types.ts b/src/utils/http/axios/types.ts index 46d3df66d..99fc46e21 100644 --- a/src/utils/http/axios/types.ts +++ b/src/utils/http/axios/types.ts @@ -28,7 +28,7 @@ export interface Result { // multipart/form-data: upload file export interface UploadFileParams { // Other parameters - data?: Indexable; + data?: Recordable; // File parameter interface field name name?: string; // file name diff --git a/types/global.d.ts b/types/global.d.ts index 0bd7f95fc..2f43d812d 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -1,91 +1,85 @@ -declare interface Fn { - (...arg: T[]): R; +import type { + App, + ComponentRenderProxy, + VNode, + ComponentPublicInstance, + FunctionalComponent, +} from 'vue'; +declare global { + declare interface Window { + // Global vue app instance + __APP__: App; + } + + export type Writable = { + -readonly [P in keyof T]: T[P]; + }; + + declare type Nullable = T | null; + declare type NonNullable = T extends null | undefined ? never : T; + declare type Recordable = Record; + declare type ReadonlyRecordable = { + readonly [key: string]: T; + }; + declare type Indexable = { + [key: string]: T; + }; + declare type DeepPartial = { + [P in keyof T]?: DeepPartial; + }; + declare type TimeoutHandle = ReturnType; + declare type IntervalHandle = ReturnType; + + declare interface ChangeEvent extends Event { + target: HTMLInputElement; + } + + declare interface WheelEvent { + path?: EventTarget[]; + } + interface ImportMetaEnv extends ViteEnv { + __: unknown; + } + + declare interface ViteEnv { + VITE_PORT: number; + VITE_USE_MOCK: boolean; + VITE_USE_PWA: boolean; + VITE_PUBLIC_PATH: string; + VITE_PROXY: [string, string][]; + VITE_GLOB_APP_TITLE: string; + VITE_GLOB_APP_SHORT_NAME: string; + VITE_USE_CDN: boolean; + VITE_DROP_CONSOLE: boolean; + VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none'; + VITE_LEGACY: boolean; + VITE_USE_IMAGEMIN: boolean; + VITE_GENERATE_UI: string; + } + + declare function parseInt(s: string | number, radix?: number): number; + + declare function parseFloat(string: string | number): number; + + namespace JSX { + // tslint:disable no-empty-interface + type Element = VNode; + // tslint:disable no-empty-interface + type ElementClass = ComponentRenderProxy; + interface ElementAttributesProperty { + $props: any; + } + interface IntrinsicElements { + [elem: string]: any; + } + interface IntrinsicAttributes { + [elem: string]: any; + } + } } -declare interface PromiseFn { - (...arg: T[]): Promise; -} - -declare interface IObj { - [key: string]: T; - [key: number]: T; -} - -declare function parseInt(s: string | number, radix?: number): number; - -declare function parseFloat(string: string | number): number; - -declare type Nullable = T | null; - -declare type NonNullable = T extends null | undefined ? never : T; - -declare type RefType = T | null; - -declare type CustomizedHTMLElement = HTMLElement & T; - -declare type Indexable = { - [key: string]: T; -}; - -declare type Recordable = Record; - -declare type ReadonlyRecordable = { - readonly [key: string]: T; -}; - -declare type Hash = Indexable; - -declare type DeepPartial = { - [P in keyof T]?: DeepPartial; -}; - -declare type LabelValueOptions = { - label: string; - value: any; -}[]; - -declare type EmitType = (event: string, ...args: any[]) => void; - -declare type TargetContext = '_self' | '_blank'; - -declare type TimeoutHandle = ReturnType; - -declare type IntervalHandle = ReturnType; - -declare interface ComponentElRef { - $el: T; -} - -declare type ComponentRef = ComponentElRef | null; - -declare type ElRef = Nullable; - -type IsSame = A | B extends A & B ? true : false; - -declare interface ChangeEvent extends Event { - target: HTMLInputElement; -} - -declare interface WheelEvent { - path?: EventTarget[]; -} - -interface ImportMetaEnv extends ViteEnv { - __: unknown; -} - -declare interface ViteEnv { - VITE_PORT: number; - VITE_USE_MOCK: boolean; - VITE_USE_PWA: boolean; - VITE_PUBLIC_PATH: string; - VITE_PROXY: [string, string][]; - VITE_GLOB_APP_TITLE: string; - VITE_GLOB_APP_SHORT_NAME: string; - VITE_USE_CDN: boolean; - VITE_DROP_CONSOLE: boolean; - VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none'; - VITE_LEGACY: boolean; - VITE_USE_IMAGEMIN: boolean; - VITE_GENERATE_UI: string; +declare module 'vue' { + export type JSXComponent = + | { new (): ComponentPublicInstance } + | FunctionalComponent; } diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 000000000..6de917784 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,26 @@ +declare interface Fn { + (...arg: T[]): R; +} + +declare interface PromiseFn { + (...arg: T[]): Promise; +} + +declare type RefType = T | null; + +declare type LabelValueOptions = { + label: string; + value: any; +}[]; + +declare type EmitType = (event: string, ...args: any[]) => void; + +declare type TargetContext = '_self' | '_blank'; + +declare interface ComponentElRef { + $el: T; +} + +declare type ComponentRef = ComponentElRef | null; + +declare type ElRef = Nullable; diff --git a/types/module.d.ts b/types/module.d.ts index afd970af5..d920e9943 100644 --- a/types/module.d.ts +++ b/types/module.d.ts @@ -1,3 +1,9 @@ +declare module '*.vue' { + import { defineComponent } from 'vue'; + const Component: ReturnType; + export default Component; +} + declare module 'ant-design-vue/es/locale/*' { import { Locale } from 'ant-design-vue/types/locale-provider'; const locale: Locale & ReadonlyRecordable; diff --git a/types/tsx.d.ts b/types/tsx.d.ts deleted file mode 100644 index 1cb0bdefc..000000000 --- a/types/tsx.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { ComponentRenderProxy, VNode } from 'vue'; - -declare global { - namespace JSX { - // tslint:disable no-empty-interface - type Element = VNode; - // tslint:disable no-empty-interface - type ElementClass = ComponentRenderProxy; - interface ElementAttributesProperty { - $props: any; - } - interface IntrinsicElements { - [elem: string]: any; - } - interface IntrinsicAttributes { - [elem: string]: any; - } - } -} diff --git a/types/vue-app-env.d.ts b/types/vue-app-env.d.ts deleted file mode 100644 index 87bc1fa54..000000000 --- a/types/vue-app-env.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare module '*.vue' { - import { defineComponent } from 'vue'; - const Component: ReturnType; - export default Component; -} diff --git a/types/window.d.ts b/types/window.d.ts deleted file mode 100644 index 15d69744a..000000000 --- a/types/window.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { App } from 'vue'; - -declare global { - declare interface Window { - // Global vue app instance - __APP__: App; - } -}