Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript] cacheKey arguments array isn't automatically typed #50

Closed
dylang opened this issue Dec 4, 2019 · 1 comment · Fixed by #69
Closed

[TypeScript] cacheKey arguments array isn't automatically typed #50

dylang opened this issue Dec 4, 2019 · 1 comment · Fixed by #69

Comments

@dylang
Copy link
Contributor

dylang commented Dec 4, 2019

In v5, the cacheKey arguments were automatically typed based on the method signature. In v6, the cacheKey arguments extend unknown instead of getting them from the original function.

Example error:

const example = mem(
  (str: string, strArray: string[]) => { /* do stuff */  },
  {
    // Typescript error on strArray: 
    // TS2461: Type 'unknown' is not an array type.
    cacheKey: ([str, strArray]) => [str, ...strArray].join()
    //                                   ^^^^^^^^^^^ <- Example error
  }
);

Workaround:

const example = mem(
  (str: string, strArray: string[]) => { /* do stuff */  },
  {
    // Repeat the types of the arguments inside of [ ].
    cacheKey: ([str, strArray]: [string, string[]]) => [str, ...strArray].join()
    //                        ^^^^^^^^^^^^^^^^^^^^ <- Example workaround
  }
);

I'm not sure if this can be fixed using generics, so it might just be some documentation for those confused when upgrading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
@dylang @fregante and others