From 401c0c563f4fa1f5bfd4e50a000086e69ae95c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=AA=E5=8D=8E=E8=A3=95?= Date: Tue, 3 Jun 2025 09:37:43 +0800 Subject: [PATCH] feat(cache): enhance tryGet method to support generic return types (#19261) --- lib/utils/cache/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils/cache/index.ts b/lib/utils/cache/index.ts index 5c1750c46..a9a70f0fc 100644 --- a/lib/utils/cache/index.ts +++ b/lib/utils/cache/index.ts @@ -71,7 +71,7 @@ export default { * @param refresh Whether to renew the cache expiration time when the cache is hit. `true` by default. * @returns */ - tryGet: async (key: string, getValueFunc: () => Promise>, maxAge = config.cache.contentExpire, refresh = true) => { + tryGet: async >(key: string, getValueFunc: () => Promise, maxAge = config.cache.contentExpire, refresh = true) => { if (typeof key !== 'string') { throw new TypeError('Cache key must be a string'); } @@ -87,7 +87,7 @@ export default { v = parsed; } - return v; + return v as T; } else { const value = await getValueFunc(); cacheModule.set(key, value, maxAge);