diff --git a/packages/hooks/src/useMemoizedFn/index.ts b/packages/hooks/src/useMemoizedFn/index.ts index 1d138a3a62..ee5765e0b6 100644 --- a/packages/hooks/src/useMemoizedFn/index.ts +++ b/packages/hooks/src/useMemoizedFn/index.ts @@ -2,6 +2,11 @@ import { useMemo, useRef } from 'react'; type noop = (this: any, ...args: any[]) => any; +type PickFunction = ( + this: ThisParameterType, + ...args: Parameters +) => ReturnType; + function useMemoizedFn(fn: T) { if (process.env.NODE_ENV === 'development') { if (typeof fn !== 'function') { @@ -15,11 +20,11 @@ function useMemoizedFn(fn: T) { // https://github.com/alibaba/hooks/issues/728 fnRef.current = useMemo(() => fn, [fn]); - const memoizedFn = useRef(); + const memoizedFn = useRef>(); if (!memoizedFn.current) { memoizedFn.current = function (this, ...args) { return fnRef.current.apply(this, args); - } as T; + }; } return memoizedFn.current;