Skip to content

Commit e74bdf7

Browse files
authored
node-cache - fix: returning T instead of any (#1131)
* node-cache - fix: returning T instead of any * Update index.test.ts
1 parent 0687a58 commit e74bdf7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

packages/node-cache/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class NodeCache extends Hookified {
178178
* @param {string | number} key if the key is a number it will convert it to a string
179179
* @returns {T} the value or undefined
180180
*/
181-
public get<T>(key: string | number): any {
181+
public get<T>(key: string | number): T | undefined {
182182
const result = this.store.get(this.formatKey(key));
183183
if (result) {
184184
if (result.ttl > 0) {
@@ -195,15 +195,15 @@ export class NodeCache extends Hookified {
195195

196196
this._stats.incrementHits();
197197
if (this.options.useClones) {
198-
return this._cacheable.clone(result.value);
198+
return this._cacheable.clone(result.value) as T;
199199
}
200200

201201
return result.value as T;
202202
}
203203

204204
this._stats.incrementHits();
205205
if (this.options.useClones) {
206-
return this._cacheable.clone(result.value);
206+
return this._cacheable.clone(result.value) as T;
207207
}
208208

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

225225
for (const key of keys) {
226226
const value = this.get(key);

packages/node-cache/test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ describe('NodeCache', () => {
286286
await sleep(1000);
287287
expect(cache.getStats().keys).toBe(2);
288288
expect(expiredKey).toBe('foo-expired');
289-
const expiredValue = cache.get('foo-expired') as string;
289+
const expiredValue = cache.get<string>('foo-expired');
290290
expect(expiredValue).toBe(undefined);
291291
cache.close();
292292
});

0 commit comments

Comments
 (0)