Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/node-cache/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class NodeCache extends Hookified {
* @param {string | number} key if the key is a number it will convert it to a string
* @returns {T} the value or undefined
*/
public get<T>(key: string | number): any {
public get<T>(key: string | number): T | undefined {
const result = this.store.get(this.formatKey(key));
if (result) {
if (result.ttl > 0) {
Expand All @@ -195,15 +195,15 @@ export class NodeCache extends Hookified {

this._stats.incrementHits();
if (this.options.useClones) {
return this._cacheable.clone(result.value);
return this._cacheable.clone(result.value) as T;
}

return result.value as T;
}

this._stats.incrementHits();
if (this.options.useClones) {
return this._cacheable.clone(result.value);
return this._cacheable.clone(result.value) as T;
}

return result.value as T;
Expand All @@ -217,10 +217,10 @@ export class NodeCache extends Hookified {
* Gets multiple saved values from the cache. Returns an empty object {} if not found or expired.
* If the value was found it returns an object with the key value pair.
* @param {Array<string | number} keys an array of keys
* @returns {Record<string, unknown>} an object with the key as a property and the value as the value
* @returns {Record<string, T | undefined>} an object with the key as a property and the value as the value
*/
public mget<T>(keys: Array<string | number>): Record<string, unknown> {
const result: Record<string, unknown> = {};
public mget<T>(keys: Array<string | number>): Record<string, T | undefined> {
const result: Record<string, T | undefined> = {};

for (const key of keys) {
const value = this.get(key);
Expand Down
2 changes: 1 addition & 1 deletion packages/node-cache/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ describe('NodeCache', () => {
await sleep(1000);
expect(cache.getStats().keys).toBe(2);
expect(expiredKey).toBe('foo-expired');
const expiredValue = cache.get('foo-expired') as string;
const expiredValue = cache.get<string>('foo-expired');
expect(expiredValue).toBe(undefined);
cache.close();
});
Expand Down