build(projects): 引入TS高级类型库

This commit is contained in:
Soybean 2022-08-24 19:21:22 +08:00
parent 639c4458be
commit 71a753f323
2 changed files with 11 additions and 0 deletions

View File

@ -109,6 +109,7 @@
"unplugin-icons": "^0.14.8", "unplugin-icons": "^0.14.8",
"unplugin-vue-components": "0.22.4", "unplugin-vue-components": "0.22.4",
"unplugin-vue-define-options": "^0.10.0", "unplugin-vue-define-options": "^0.10.0",
"utility-types": "^3.10.0",
"vite": "^3.0.9", "vite": "^3.0.9",
"vite-plugin-compression": "^0.5.1", "vite-plugin-compression": "^0.5.1",
"vite-plugin-html": "^3.2.0", "vite-plugin-html": "^3.2.0",

View File

@ -10,4 +10,14 @@ declare namespace TypeUtil {
type FirstOfArray<T extends any[]> = T extends [infer First, ...infer _Rest] ? First : never; type FirstOfArray<T extends any[]> = T extends [infer First, ...infer _Rest] ? First : never;
type LastOfArray<T extends any[]> = T extends [...infer _Rest, infer Last] ? Last : never; type LastOfArray<T extends any[]> = T extends [...infer _Rest, infer Last] ? Last : never;
// union to tuple
type Union2IntersectionFn<T> = (T extends unknown ? (k: () => T) => void : never) extends (k: infer R) => void
? R
: never;
type GetUnionLast<U> = Union2IntersectionFn<U> extends () => infer I ? I : never;
type UnionToTuple<T, R extends any[] = []> = [T] extends [never]
? R
: UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...R]>;
} }