File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,10 +23,10 @@ export const useThrottle = <T extends unknown[]>(fn: (...args: T) => void | Prom
2323 fn ( ...args ) ;
2424 idRef . current = setTimeout ( ( ) => pending . current = false , optsRef . current . delay ) ;
2525 } else if ( optsRef . current . waitFn ) {
26- if ( isAsync ( fn ) ) {
27- ( fn ( ...args ) as Promise < ReturnType < typeof fn > > ) . finally ( ( ) => pending . current = false ) ;
26+ const current = fn ( ...args ) ;
27+ if ( isAsync ( current ) ) {
28+ ( current as Promise < void > ) . finally ( ( ) => pending . current = false ) ;
2829 } else {
29- fn ( ...args ) ;
3030 pending . current = false ;
3131 }
3232 } else {
Original file line number Diff line number Diff line change 11/**
22 * **`isAsync`**: It detects if a function is asynchronous.
3- * @param {(...args: unknown[])=> Eìunknown | Promise<unknown> }
3+ * @param {(...args: unknown[])=> unknown | Promise<unknown> }
44 * @returns {boolean } result
55 */
6- export const isAsync = < T extends unknown [ ] , E = unknown > ( fn : ( ...args : T ) => E | Promise < E > ) : boolean => {
7- return fn . constructor . name === "AsyncFunction" || ( typeof fn === "function" && typeof fn === "object" && typeof ( fn as PromiseLike < E > ) . then === "function" ) ;
6+ export const isAsync = < T extends unknown [ ] , E = unknown > ( fn : E | Promise < E > | ( ( ...args : T ) => E | Promise < E > ) ) : boolean => {
7+ return ( typeof fn === "function" && fn . constructor . name === "AsyncFunction" ) || ( typeof fn === "object" && typeof ( fn as PromiseLike < E > ) . then === "function" ) ;
88}
You can’t perform that action at this time.
0 commit comments