Skip to content

Commit

Permalink
build(projects): 引入TS高级类型库
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Aug 24, 2022
1 parent 639c445 commit 71a753f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -109,6 +109,7 @@
"unplugin-icons": "^0.14.8",
"unplugin-vue-components": "0.22.4",
"unplugin-vue-define-options": "^0.10.0",
"utility-types": "^3.10.0",
"vite": "^3.0.9",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-html": "^3.2.0",
Expand Down
10 changes: 10 additions & 0 deletions src/typings/utils.d.ts
Expand Up @@ -10,4 +10,14 @@ declare namespace TypeUtil {
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;

// 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]>;
}

0 comments on commit 71a753f

Please sign in to comment.