From b42fdd78b86a1f03d2cdda7c952430fdea996c69 Mon Sep 17 00:00:00 2001 From: iapyang Date: Wed, 23 Oct 2019 17:28:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BB=A3=E7=A0=81=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typescript/core/decorator/decorator.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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