diff --git a/typescript/core/decorator/decorator.ts b/typescript/core/decorator/decorator.ts index 63437a9f1e..d7e7e664f5 100644 --- a/typescript/core/decorator/decorator.ts +++ b/typescript/core/decorator/decorator.ts @@ -59,3 +59,28 @@ export class Model unknown} | {}; } + +/* 分享一段很好看的代码 +// union to intersection of functions +type UnionToIoF = + (U extends any ? (k: (x: U) => void) => void : never) extends + ((k: infer I) => void) ? I : never + +// return last element from Union +type UnionPop = UnionToIoF extends { (a: infer A): void; } ? A : never; + +// prepend an element to a tuple. +type Prepend> = + ((a: U, ...r: T) => void) extends (...r: infer R) => void ? R : never; + +type UnionToTupleRecursively> = { + 1: Result; + 0: UnionToTupleRecursively_, Result>; + // 0: UnionToTupleRecursively>, Prepend, Result>> +}[[Union] extends [never] ? 1 : 0]; + +type UnionToTupleRecursively_> = + UnionToTupleRecursively, Prepend>; + +type UnionToTuple = UnionToTupleRecursively; +*/ \ No newline at end of file