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

Typings for Cache.Createoption #78

Open
stefanosandes opened this issue Jul 26, 2019 · 3 comments
Open

Typings for Cache.Createoption #78

stefanosandes opened this issue Jul 26, 2019 · 3 comments

Comments

@stefanosandes
Copy link

In the typings, the cache is expecting an object that not includes a Create method. It's correct? What's the right way to use it with Typescript?

export interface Cache<K, V> {
  get(key: K): V;
  set(key: K, value: V): void;
  has(key: K): boolean;
}

export type Serializer = (args: any[]) => string;

export interface Options<F extends Func> {
  cache?: Cache<string, ReturnType<F>>;
  serializer?: Serializer;
  strategy?: MemoizeFunc;
}

The tslint error output:

Argument of type '{ cache: { create(): { has(key: any): boolean; get(key: any): any; set(key: any, value: any): void; }; }; }' is not assignable to parameter of type 'Options<() => string>'.
  Types of property 'cache' are incompatible.
    Type '{ create(): { has(key: any): boolean; get(key: any): any; set(key: any, value: any): void; }; }' is not assignable to type 'Cache<string, string>'.
      Object literal may only specify known properties, and 'create' does not exist in type 'Cache<string, string>'.ts(2345)
@martinschayna
Copy link

Looks like there is the same bug for Flowtype either (see flow-typed repo, maybe automatic conversion from TS?). Documentation and source code use create.

@tdev9 tdev9 mentioned this issue Mar 1, 2020
@tdev9
Copy link
Contributor

tdev9 commented Mar 1, 2020

I've created this PR: #80 which will fix it.

@tdev9
Copy link
Contributor

tdev9 commented Apr 19, 2020

I guess it should be closed because #80 has fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants