Improve typing precision of CacheProvider.get()
This commit is contained in:
parent
9d42167013
commit
f41a456524
@ -1,5 +1,5 @@
|
||||
export default interface CacheProvider {
|
||||
get(key: string, defaultValue?: string): Promise<string | null>;
|
||||
get<T extends string | undefined>(key: string, defaultValue?: T): Promise<T>;
|
||||
|
||||
has(key: string): Promise<boolean>;
|
||||
|
||||
|
@ -42,8 +42,8 @@ export default class RedisComponent extends ApplicationComponent implements Cach
|
||||
return this.redisClient !== undefined && this.redisClient.connected;
|
||||
}
|
||||
|
||||
public async get(key: string, defaultValue?: string): Promise<string | null> {
|
||||
return await new Promise<string | null>((resolve, reject) => {
|
||||
public async get<T extends string | undefined>(key: string, defaultValue?: T): Promise<T> {
|
||||
return await new Promise<T>((resolve, reject) => {
|
||||
if (!this.redisClient) {
|
||||
reject(`Redis store was not initialized.`);
|
||||
return;
|
||||
@ -54,13 +54,13 @@ export default class RedisComponent extends ApplicationComponent implements Cach
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve(val || defaultValue || null);
|
||||
resolve((val || defaultValue || undefined) as T);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public async has(key: string): Promise<boolean> {
|
||||
return await this.get(key) !== null;
|
||||
return await this.get(key) !== undefined;
|
||||
}
|
||||
|
||||
public async forget(key: string): Promise<void> {
|
||||
|
Loading…
Reference in New Issue
Block a user