From 4fa41bab0021f13250c7b643f77f3894cba21e3e Mon Sep 17 00:00:00 2001 From: "Xavier.Meng" Date: Sun, 1 Jan 2023 05:23:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=20refactor(base/extend):=20?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B3=9B=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typescript/core/base.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/typescript/core/base.ts b/typescript/core/base.ts index 79dc317af..e681f2ac4 100644 --- a/typescript/core/base.ts +++ b/typescript/core/base.ts @@ -177,7 +177,8 @@ export interface _base { functions: (object: object) => string[]; - extend: (object: object, ...sources: any[]) => object; + extend(object: T): T; + extend(object: T, ...sources: U[]): T & UnionToIntersection; defaults: (object: object, ...sources: any[]) => object; @@ -399,3 +400,11 @@ type merge = { deepExtend(object: any, ...otherArgs: any[]): any; } + +type UnionToIntersection = ( + Union extends unknown + ? (x: Union) => void + : never +) extends ((x: infer Intersection) => void) + ? Intersection + : never;