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:
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;
.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>;
MickL commented
I created a PR: DefinitelyTyped/DefinitelyTyped#50499
BryanDonovan commented
Thanks!
MickL commented
@BlackDark even updated more DefinitelyTyped/DefinitelyTyped#50600
BlackDark commented
@BryanDonovan can be closed.
See https://www.npmjs.com/package/@types/cache-manager/v/3.4.0