rivo
Version:
🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
46 lines (42 loc) • 1.38 kB
TypeScript
// @ts-ignore - Only used in doc comments
import type { Merge } from "./Merge";
// @ts-ignore - Only used in doc comments
import type MergeFn from "./Merge";
import type { Args, Fn } from "../HKT";
type _Id<O> = { [K in keyof O]: O[K] };
/**
* Simply merge two objects together without considering optional properties.
*
* It is recommended to use to optimize performance when you're sure that
* the two objects have no optional properties, otherwise use {@link Merge}.
*
* Sig: `(l: object, r: object) => object`
*
* @example
* ```typescript
* type A = { a: number; b: string };
* type B = { a: boolean; c: string };
* type R = SimpleMerge<A, B>;
* // ^?: { a: boolean; b: string; c: string }
* ```
*
* @see {@link Merge}
*/
export type SimpleMerge<L extends object, R extends object> = _Id<{
[K in keyof L | keyof R]: K extends keyof R ? R[K]
: K extends keyof L ? L[K]
: never;
}>;
/**
* Fn] Simply merge two objects together without considering optional properties.
*
* It is recommended to use to optimize performance when you're sure that
* the two objects have no optional properties, otherwise use {@link MergeFn}.
*
* Sig: `(l: object, r: object) => object`
*
* @see {@link MergeFn}
*/
export default interface SimpleMergeFn extends Fn<[object, object], object> {
def: ([l, r]: Args<this>) => SimpleMerge<typeof l, typeof r>;
}