diff --git a/components/_util/getRenderPropValue.ts b/components/_util/getRenderPropValue.ts index 50b2e6de9e..fe673166b5 100644 --- a/components/_util/getRenderPropValue.ts +++ b/components/_util/getRenderPropValue.ts @@ -9,9 +9,8 @@ export const getRenderPropValue = ( return null; } - const isRenderFunction = typeof propValue === 'function'; - if (isRenderFunction) { - return (propValue as RenderFunction)(); + if (typeof propValue === 'function') { + return propValue(); } return propValue; diff --git a/components/_util/hooks/useSyncState.ts b/components/_util/hooks/useSyncState.ts index cbb6434ba3..03fcb47097 100644 --- a/components/_util/hooks/useSyncState.ts +++ b/components/_util/hooks/useSyncState.ts @@ -1,7 +1,7 @@ import * as React from 'react'; import useForceUpdate from './useForceUpdate'; -type UseSyncStateProps = [() => T, (newValue: T) => void]; +type UseSyncStateProps = readonly [() => T, (newValue: T) => void]; export default function useSyncState(initialValue: T): UseSyncStateProps { const ref = React.useRef(initialValue); @@ -14,5 +14,5 @@ export default function useSyncState(initialValue: T): UseSyncStateProps { // re-render forceUpdate(); }, - ]; + ] as const; } diff --git a/components/badge/ScrollNumber.tsx b/components/badge/ScrollNumber.tsx index f5cd1f5fb6..6e09cc2f44 100644 --- a/components/badge/ScrollNumber.tsx +++ b/components/badge/ScrollNumber.tsx @@ -75,7 +75,7 @@ const ScrollNumber: React.FC = ({ className: classNames(`${prefixCls}-custom-component`, oriProps?.className, motionClassName), })); } - return React.createElement(component as any, newProps, numberNodes); + return React.createElement(component, newProps, numberNodes); }; export default ScrollNumber; diff --git a/components/dropdown/dropdown.tsx b/components/dropdown/dropdown.tsx index 42601aba60..f3f02f7d7d 100644 --- a/components/dropdown/dropdown.tsx +++ b/components/dropdown/dropdown.tsx @@ -213,7 +213,7 @@ const Dropdown: DropdownInterface = props => { if (menu?.items) { overlayNode = ; } else if (typeof overlay === 'function') { - overlayNode = (overlay as OverlayFunc)(); + overlayNode = overlay(); } else { overlayNode = overlay; } diff --git a/components/input/hooks/useRemovePasswordTimeout.ts b/components/input/hooks/useRemovePasswordTimeout.ts index 660d72bcb2..c3d6006798 100644 --- a/components/input/hooks/useRemovePasswordTimeout.ts +++ b/components/input/hooks/useRemovePasswordTimeout.ts @@ -5,10 +5,10 @@ export default function useRemovePasswordTimeout( inputRef: React.RefObject, triggerOnMount?: boolean, ) { - const removePasswordTimeoutRef = useRef([]); + const removePasswordTimeoutRef = useRef([]); const removePasswordTimeout = () => { removePasswordTimeoutRef.current.push( - window.setTimeout(() => { + setTimeout(() => { if ( inputRef.current?.input && inputRef.current?.input.getAttribute('type') === 'password' && @@ -25,7 +25,12 @@ export default function useRemovePasswordTimeout( removePasswordTimeout(); } - return () => removePasswordTimeoutRef.current.forEach(item => window.clearTimeout(item)); + return () => + removePasswordTimeoutRef.current.forEach(timer => { + if (timer) { + clearTimeout(timer); + } + }); }, []); return removePasswordTimeout; diff --git a/components/modal/useModal/index.tsx b/components/modal/useModal/index.tsx index d51b7a19dc..97cf0fa29e 100644 --- a/components/modal/useModal/index.tsx +++ b/components/modal/useModal/index.tsx @@ -28,7 +28,7 @@ const ElementsHolder = React.memo( ); export default function useModal(): [Omit, React.ReactElement] { - const holderRef = React.useRef(null as any); + const holderRef = React.useRef(null); // ========================== Effect ========================== const [actionQueue, setActionQueue] = React.useState<(() => void)[]>([]); @@ -52,14 +52,14 @@ export default function useModal(): [Omit, React.R const modalRef = React.createRef(); - let closeFunc: Function; + let closeFunc: Function | undefined; const modal = ( { - closeFunc(); + closeFunc?.(); }} /> ); diff --git a/components/timeline/Timeline.tsx b/components/timeline/Timeline.tsx index ca8f55a674..090f1a4e73 100644 --- a/components/timeline/Timeline.tsx +++ b/components/timeline/Timeline.tsx @@ -45,7 +45,7 @@ const Timeline: TimelineType = props => { ) : null; const timeLineItems = React.Children.toArray(children); - timeLineItems.push(pendingItem as any); + timeLineItems.push(pendingItem!); if (reverse) { timeLineItems.reverse(); } diff --git a/components/typography/hooks/useMergedConfig.ts b/components/typography/hooks/useMergedConfig.ts index 66c5b02fc7..bd16c97e62 100644 --- a/components/typography/hooks/useMergedConfig.ts +++ b/components/typography/hooks/useMergedConfig.ts @@ -3,8 +3,8 @@ import * as React from 'react'; export default function useMergedConfig( propConfig: any, templateConfig?: Target, -): [boolean, Target] { - return React.useMemo(() => { +): readonly [boolean, Target] { + return React.useMemo(() => { const support = !!propConfig; return [ @@ -13,6 +13,6 @@ export default function useMergedConfig( ...templateConfig, ...(support && typeof propConfig === 'object' ? propConfig : null), }, - ]; + ] as const; }, [propConfig]); } diff --git a/components/typography/hooks/useUpdatedEffect.ts b/components/typography/hooks/useUpdatedEffect.ts index 53141df476..ec85286161 100644 --- a/components/typography/hooks/useUpdatedEffect.ts +++ b/components/typography/hooks/useUpdatedEffect.ts @@ -1,7 +1,7 @@ import * as React from 'react'; /** Similar with `useEffect` but only trigger after mounted */ -export default (callback: () => void, conditions: any[]) => { +const useUpdatedEffect = (callback: () => void, conditions?: React.DependencyList) => { const mountRef = React.useRef(false); React.useEffect(() => { @@ -12,3 +12,5 @@ export default (callback: () => void, conditions: any[]) => { } }, conditions); }; + +export default useUpdatedEffect;