react-use
react-use copied to clipboard
Improve useAsync's typings
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch [email protected] for the project I'm working on.
This makes useAsync infer the type of the promise that's passed to it, and propagate it onwards to value, even when the function passed is not async.
Before:
After:
Here is the diff that solved my problem:
diff --git a/node_modules/react-use/lib/misc/types.d.ts b/node_modules/react-use/lib/misc/types.d.ts
index bc1a776..fbb2ec6 100644
--- a/node_modules/react-use/lib/misc/types.d.ts
+++ b/node_modules/react-use/lib/misc/types.d.ts
@@ -1,2 +1,2 @@
export declare type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
-export declare type FunctionReturningPromise = (...args: any[]) => Promise<any>;
+export declare type FunctionReturningPromise<T> = (...args: any[]) => Promise<T>;
This issue body was partially generated by patch-package.