From 38b7231a94a3d1803ea3ca7cad9c4578df8b9348 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Sat, 21 Dec 2024 09:36:05 -0300 Subject: [PATCH] feat: crating assignEx --- src/dummies.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dummies.ts b/src/dummies.ts index 5898375..a131d4e 100644 --- a/src/dummies.ts +++ b/src/dummies.ts @@ -1,4 +1,4 @@ -import { hasLength } from './guards'; +import { hasLength, isObject } from './guards'; import { Lenghtable, Sizeable } from './types'; export function identity(x: T) { @@ -76,6 +76,12 @@ export function compareProp( return (t: T) => comparer(t[k]); } +export function assignEx(a: A, b: B): unknown extends A ? B : A & B { + return (isObject(a) ? Object.assign(a, b) : { ...b }) as unknown extends A + ? B + : A & B; +} + export const nodeVersion = Number(process.versions.node.split('.')[0]); const TIMERS_PROMISE_FIRST_APPEARANCE = 16;