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": {