UNPKG

@politie/sherlock-utils

Version:

Utility functions that are designed to work with Sherlock. His toolbelt.

23 lines (22 loc) 1.05 kB
import { Derivable } from '@politie/sherlock'; /** * Converts a map or array of Derivables or any nested structure containing maps, arrays and Derivables into a single * Derivable with all nested Derivables unwrapped into it. * * const obj = { key1: atom(123), key2: atom(456) }; * const obj$ = struct<typeof obj, number>(obj); * expect(obj$.get()).to.deep.equal({ key1: 123, key2: 456 }); * * It only touches Arrays, plain Objects and Derivables, the rest is simply returned inside the Derivable as-is. * * @param obj the object to deepunwrap into a derivable */ export declare function struct<V>(obj: Derivable<V>): Derivable<V>; export declare function struct<I extends Record<string, Derivable<V>>, V>(obj: I): Derivable<{ [P in keyof I]: V; }>; export declare function struct<I extends Array<Derivable<V>>, V>(obj: I): Derivable<V[]>; export declare function struct<I extends any[]>(obj: I): Derivable<any[]>; export declare function struct<I extends object | any[]>(obj: I): Derivable<{ [P in keyof I]: any; }>;