@monstermann/fn
Version:
A utility library for TypeScript.
25 lines (24 loc) • 837 B
TypeScript
import { Simplify } from "type-fest";
//#region src/object/matches.d.ts
type Matches<T extends object, U extends T> = T extends unknown ? U extends T ? Simplify<T & U> : never : never;
/**
* `matches(target, props)`
*
* Checks if all properties in `props` object have equal values in `target` object.
*
* ```ts
* matches({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 }); // true
* matches({ a: 1, b: 2, c: 3 }, { a: 1, b: 3 }); // false
* ```
*
* ```ts
* pipe({ a: 1, b: 2, c: 3 }, matches({ a: 1, b: 2 })); // true
* pipe({ a: 1, b: 2, c: 3 }, matches({ a: 1, b: 3 })); // false
* ```
*/
declare const matches: {
<T extends object, U extends T>(props: Partial<U>): (target: T) => target is Matches<T, U>;
<T extends object, U extends T>(target: T, props: Partial<U>): target is Matches<T, U>;
};
//#endregion
export { matches };