From 03b3f88424f718073513a22d2a3ab5dc13e15b90 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 18 Jan 2019 11:36:10 -0500 Subject: [PATCH] Provide TypeScript types for the public API. --- lib/index.d.ts | 20 ++++++++++++++++++++ package.json | 1 + 2 files changed, 21 insertions(+) create mode 100644 lib/index.d.ts diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..b2217e4 --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,20 @@ +export type OptimisticWrapperFunction< + T = (...args: any[]) => any, +> = T & { + // The .dirty(...) method of an optimistic function takes exactly the + // same parameter types as the original function. + dirty: T; +}; + +export type OptimisticWrapOptions = { + max?: number; + disposable?: boolean; + makeCacheKey?(...args: any[]): any; +}; + +export declare function defaultMakeCacheKey(...args: any[]): object; + +export declare function wrap( + originalFunction: T, + options?: OptimisticWrapOptions, +): OptimisticWrapperFunction; diff --git a/package.json b/package.json index 490cfc4..cd6e99c 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "memoization" ], "main": "lib/index.js", + "types": "lib/index.d.ts", "license": "MIT", "homepage": "https://github.com/benjamn/optimism#readme", "repository": {