From de29a110da420484fb5944b7c4111d1e58392c98 Mon Sep 17 00:00:00 2001 From: K <1175047471@qq.com> Date: Fri, 22 Mar 2024 09:22:52 +0800 Subject: [PATCH] chore: cleanup --- .../Form/src/components/ApiTree.vue | 2 +- .../Form/src/components/ApiTreeSelect.vue | 1 - .../Form/src/components/FormItem.vue | 1 - src/components/Scrollbar/src/Scrollbar.vue | 2 +- src/components/Scrollbar/src/util.ts | 22 ----- src/hooks/event/useWindowSizeFn.ts | 2 +- src/types/utils.d.ts | 28 +++++-- src/utils/props.ts | 2 +- src/utils/types.ts | 82 ------------------- 9 files changed, 23 insertions(+), 119 deletions(-) delete mode 100644 src/utils/types.ts diff --git a/src/components/Form/src/components/ApiTree.vue b/src/components/Form/src/components/ApiTree.vue index fc392c4b..4a55d11b 100644 --- a/src/components/Form/src/components/ApiTree.vue +++ b/src/components/Form/src/components/ApiTree.vue @@ -7,7 +7,7 @@ import type { DataNode } from 'ant-design-vue/es/tree' import { isArray, isFunction } from '@/utils/is' import { handleTree as handleTreeFn } from '@/utils/tree' import { propTypes } from '@/utils/propTypes' -import type { AnyFunction, Recordable } from '@/utils/types' +import type { AnyFunction } from '@/types/utils' import { useRuleFormItem } from '@/hooks/component/useFormItem' defineOptions({ name: 'ApiTree' }) diff --git a/src/components/Form/src/components/ApiTreeSelect.vue b/src/components/Form/src/components/ApiTreeSelect.vue index d9fb7818..512c2259 100644 --- a/src/components/Form/src/components/ApiTreeSelect.vue +++ b/src/components/Form/src/components/ApiTreeSelect.vue @@ -5,7 +5,6 @@ import { get, set } from 'lodash-es' import { LoadingOutlined } from '@ant-design/icons-vue' import { isArray, isFunction } from '@/utils/is' import { propTypes } from '@/utils/propTypes' -import type { Recordable } from '@/utils/types' import { handleTree as handleTreeFn } from '@/utils/tree' defineOptions({ name: 'ApiTreeSelect' }) diff --git a/src/components/Form/src/components/FormItem.vue b/src/components/Form/src/components/FormItem.vue index 5ec33869..34e7db8b 100644 --- a/src/components/Form/src/components/FormItem.vue +++ b/src/components/Form/src/components/FormItem.vue @@ -13,7 +13,6 @@ import type { TableActionType } from '@/components/Table' import { BasicHelp } from '@/components/Basic' import { isBoolean, isFunction, isNull } from '@/utils/is' import { getSlot } from '@/utils/helper/tsxHelper' -import type { Nullable, Recordable } from '@/utils/types' import { useI18n } from '@/hooks/web/useI18n' export default defineComponent({ diff --git a/src/components/Scrollbar/src/Scrollbar.vue b/src/components/Scrollbar/src/Scrollbar.vue index da4e8aec..28be8046 100644 --- a/src/components/Scrollbar/src/Scrollbar.vue +++ b/src/components/Scrollbar/src/Scrollbar.vue @@ -3,7 +3,7 @@ import type { PropType } from 'vue' import { nextTick, onBeforeUnmount, onMounted, provide, ref, unref, watch } from 'vue' import Bar from './bar' import { addResizeListener, removeResizeListener } from '@/utils/event' -import type { StyleValue } from '@/utils/types' +import type { StyleValue } from '@/types/utils' import componentSetting from '@/settings/componentSetting' defineOptions({ name: 'Scrollbar' }) diff --git a/src/components/Scrollbar/src/util.ts b/src/components/Scrollbar/src/util.ts index 198cff7e..452f6ce1 100644 --- a/src/components/Scrollbar/src/util.ts +++ b/src/components/Scrollbar/src/util.ts @@ -1,5 +1,4 @@ import type { BarMap } from './types' -import type { MergeAll } from '@/utils/types' export const BAR_MAP: BarMap = { vertical: { @@ -35,24 +34,3 @@ export function renderThumbStyle({ move, size, bar }) { return style } - -function extend(to: T, _from: K): T & K { - return Object.assign(to as any, _from) -} - -/** - * [ - * { name: 'zhangsan', age: 18 }, - * { sex: 'male', age: 20 } - * ] - * => - * { name: 'zhangsan', sex: 'male', age: 20 } - */ -export function toObject(arr: T): MergeAll { - const res = {} as MergeAll - for (let i = 0; i < arr.length; i++) { - if (arr[i]) - extend(res, arr[i]) - } - return res -} diff --git a/src/hooks/event/useWindowSizeFn.ts b/src/hooks/event/useWindowSizeFn.ts index 164c7634..342c20b4 100644 --- a/src/hooks/event/useWindowSizeFn.ts +++ b/src/hooks/event/useWindowSizeFn.ts @@ -1,5 +1,5 @@ import { tryOnMounted, tryOnUnmounted, useDebounceFn } from '@vueuse/core' -import type { AnyFunction } from '@/utils/types' +import type { AnyFunction } from '@/types/utils' interface UseWindowSizeOptions { wait?: number diff --git a/src/types/utils.d.ts b/src/types/utils.d.ts index 9a6bbbd4..a9d56614 100644 --- a/src/types/utils.d.ts +++ b/src/types/utils.d.ts @@ -1,14 +1,24 @@ -import type { ComputedRef, Ref } from 'vue' +import type { CSSProperties, ComputedRef, Ref } from 'vue' export type DynamicProps = { [P in keyof T]: Ref | T[P] | ComputedRef } -export type StringLiteralsToType - = T extends 'string' - ? string - : T extends 'number' - ? number - : T extends 'boolean' - ? boolean - : never +export type StyleValue = string | CSSProperties | Array + +/** + * 任意类型的异步函数 + */ +export type AnyPromiseFunction = (...arg: any[]) => PromiseLike + +/** + * 任意类型的普通函数 + */ +export type AnyNormalFunction = (...arg: any[]) => any + +/** + * 任意类型的函数 + */ +export type AnyFunction = AnyNormalFunction | AnyPromiseFunction + +export type Mutable = { -readonly [P in keyof T]: T[P] } diff --git a/src/utils/props.ts b/src/utils/props.ts index f7dfb56b..c68b6737 100644 --- a/src/utils/props.ts +++ b/src/utils/props.ts @@ -3,7 +3,7 @@ import { warn } from 'vue' import { fromPairs } from 'lodash-es' import type { ExtractPropTypes } from 'vue' -import type { Mutable } from './types' +import type { Mutable } from '@/types/utils' import { isObject } from '@/utils/is' const wrapperKey = Symbol('wrapperKey') diff --git a/src/utils/types.ts b/src/utils/types.ts deleted file mode 100644 index e8cae3dc..00000000 --- a/src/utils/types.ts +++ /dev/null @@ -1,82 +0,0 @@ -// copy from element-plus - -import type { CSSProperties, Plugin } from 'vue' - -type OptionalKeys> = { - [K in keyof T]: T extends Record ? never : K -}[keyof T] - -type RequiredKeys> = Exclude> - -type MonoArgEmitter = (evt: K, arg?: T[K]) => void - -type BiArgEmitter = (evt: K, arg: T[K]) => void - -export type EventEmitter> = MonoArgEmitter> & BiArgEmitter> - -/** - * 任意类型的异步函数 - */ -export type AnyPromiseFunction = (...arg: any[]) => PromiseLike - -/** - * 任意类型的普通函数 - */ -export type AnyNormalFunction = (...arg: any[]) => any - -/** - * 任意类型的函数 - */ -export type AnyFunction = AnyNormalFunction | AnyPromiseFunction - -export type PartialReturnType unknown> = Partial> - -export type SFCWithInstall = T & Plugin - -export type Nullable = T | null - -/** - * 字符串类型对象 - */ -export type Recordable = Record - -export type RefElement = Nullable - -export type CustomizedHTMLElement = HTMLElement & T - -export interface Indexable { - [key: string]: T -} - -export type Hash = Indexable - -export type TimeoutHandle = ReturnType - -export type ComponentSize = 'large' | 'medium' | 'small' | 'mini' - -export type StyleValue = string | CSSProperties | Array - -export type Mutable = { -readonly [P in keyof T]: T[P] } - -type Merge = { - [K in keyof O | keyof T]: K extends keyof T ? T[K] : K extends keyof O ? O[K] : never; -} - -/** - * T = [ - * { name: string; age: number; }, - * { sex: 'male' | 'female'; age: string } - * ] - * => - * MergeAll = { - * name: string; - * sex: 'male' | 'female'; - * age: string - * } - */ -export type MergeAll = T extends [ - infer F extends object, - ...infer Rest extends object[], -] - ? MergeAll> - : R