Skip to main content
Module

x/ts_toolbelt_unofficial/mod.ts>Object.Merge

👷 TypeScript's largest type utility library, now on Deno
Latest
type alias Object.Merge
import { type Object } from "https://deno.land/x/ts_toolbelt_unofficial@1.1.0/mod.ts";
const { Merge } = Object;

Accurately merge the fields of O with the ones of O1. It is equivalent to the spread operator in JavaScript. [[Union]]s and [[Optional]] fields will be handled gracefully.

(⚠️ needs --strictNullChecks enabled)

Examples

Example 1

import {O} from 'ts-toolbelt.ts'

type O = {
 name?: string
 age? : number
 zip? : string
 pay  : {
     cvv?: number
 }
}

type O1 = {
 age : number
 zip?: number
 city: string
 pay : {
     cvv : number
     ccn?: string
 }
}

type test = O.Merge<O, O1, 'deep'>
// {
//     name?: string;
//     age: number;
//     zip?: string | number;
//     pay: {
//         cvv: number;
//         ccn?: string;
//     };
//     city: string;
// }

Type Parameters

O extends object
O1 extends object
optional
depth extends Depth = "flat"
optional
ignore extends object = BuiltIn
optional
fill extends any = undefined
definition: { flat: MergeFlat<O, O1, ignore, fill>; deep: MergeDeep<O, O1, ignore, fill>; }[depth]