UNPKG

thorish

Version:

This is a library of useful JS concepts and data structures for Node and the browser. It it, unashamedly, a dumping ground for code needed by [@samthor](https://twitter.com/samthor)'s projects.

22 lines (21 loc) 905 B
/** * Returns the passed `Record` with only the specified extra keys made required, all others are * allowed to be `undefined`. */ export type RequiredValues<X extends Record<string | symbol, any>, K extends keyof X> = { [P in K]: X[P]; } & { [P in Exclude<keyof X, K>]: X[P] | undefined; }; /** * Prepares/builds an object and callback which is `useEffect`-like. * * The returned object is actually a `Proxy`, and when values are changed, the callback is * invoked synchronously (as part of the set). * * This limits updates to those where the `required` fields are defined (second arg of `build`). * The second `build()` layer is to allow TypeScript to infer types. */ export declare function prepareEffectTrigger<X extends Record<string | symbol, any>>(): { build<K extends keyof X>(cb: (signal: AbortSignal, values: RequiredValues<X, K>) => any, required?: K[]): Partial<X>; };