jaredwray/cacheable

Some types are not correct (?)

MickL opened this issue · 4 comments

MickL commented

I wonder if @types/cache-manager are correct. I found two things:

  1. cacheManager.set('key', { hello: 'world' }) is not possible because set requires at least 3 properties.

Suggestion:

set<T>(key: string, value: T): Promise<any>;
set<T>(key: string, value: T, options: CachingConfig): Promise<any>;
set<T>(key: string, value: T, ttl: number): Promise<any>;
set<T>(key: string, value: T, options: CachingConfig, callback: (error: any) => void): void;
set<T>(key: string, value: T, ttl: number, callback: (error: any) => void): void;
  1. .get() accepts a generic but does not return it. Therefor typings are lost and the generic is useless:
const cachedEntry = await cacheManager.get<MyInterface>('key');
// -> cachedEntry is of type any instead of MyInterface

Suggestion:

get<T>(key: string, callback: (error: any, result: T) => void): void;
get<T>(key: string): Promise<T>;

Thanks!