sodiray / radash

Functional utility library - modern, simple, typed, powerful
https://radash-docs.vercel.app
MIT License
4.1k stars 160 forks source link

The `key` option for `memo` has its argument typed as `any`, which could lead to bugs #378

Closed zlalvani closed 6 months ago

zlalvani commented 6 months ago

Here's the type definition for the memo function:

/**
 * Creates a memoized function. The returned function
 * will only execute the source function when no value
 * has previously been computed. If a ttl (milliseconds)
 * is given previously computed values will be checked
 * for expiration before being returned.
 */
declare const memo: <TFunc extends (...args: any) => any>(func: TFunc, options?: {
    key?: Func<any, string>;
    ttl?: number;
}) => TFunc;

The key option has its argument type set to any, but I believe it should be possible to infer its type from TFunc.