From ea05353ce1b724a003ce36745d6d91b41f10ca7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mahieu?= Date: Wed, 27 Sep 2023 12:24:21 +0200 Subject: [PATCH] feat: memoize: add typescript definition (#195) --- packages/memoize/package.json | 3 ++- packages/memoize/src/index.d.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 packages/memoize/src/index.d.ts diff --git a/packages/memoize/package.json b/packages/memoize/package.json index 468fa0b9..8098fcfe 100644 --- a/packages/memoize/package.json +++ b/packages/memoize/package.json @@ -46,5 +46,6 @@ "license": "MIT", "publishConfig": { "access": "public" - } + }, + "types": "./src/index.d.ts" } diff --git a/packages/memoize/src/index.d.ts b/packages/memoize/src/index.d.ts new file mode 100644 index 00000000..f4016c73 --- /dev/null +++ b/packages/memoize/src/index.d.ts @@ -0,0 +1,18 @@ +import { Options, Store } from '@keyvhq/core' + +declare function memoize ( + fn: (...args: Args) => Promise, + keyvOptions: Options | Store, + options: { + key?: (value: RawResult) => any + objectMode?: boolean + staleTtl?: number | boolean | ((value: any) => number | boolean) + ttl?: number | ((value: any) => number) + // Difficult to type this one, so we'll just leave it as any + // When options.value is not provided, the return type of the memoized function is Result + // I can't figure out how to type this, so I'm just going to leave it as any + value?: (value: RawResult) => Result + } +): (...args: Args) => Promise + +export default memoize