Skip to content

Commit

Permalink
feat: memoize: add typescript definition (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
LoicMahieu authored Sep 27, 2023
1 parent c5409be commit ea05353
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/memoize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
"license": "MIT",
"publishConfig": {
"access": "public"
}
},
"types": "./src/index.d.ts"
}
18 changes: 18 additions & 0 deletions packages/memoize/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Options, Store } from '@keyvhq/core'

declare function memoize<RawResult, Result, Args extends any[]> (
fn: (...args: Args) => Promise<RawResult>,
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<RawResult>

export default memoize

0 comments on commit ea05353

Please sign in to comment.