Skip to content

Typings for Cache.Createoption #78

@stefanosandes

Description

@stefanosandes

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions