From ac47eaa9d7aaccd8ae0ebb790767c709b71e028b Mon Sep 17 00:00:00 2001 From: aojunhao123 <1844749591@qq.com> Date: Wed, 1 Jul 2026 23:42:22 +0800 Subject: [PATCH 1/2] fix: remove unnecessary/unsafe type assertions in RawList and VirtualList MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two scroll-config casts were dead weight — control-flow narrowing already produced the correct type. The forwardRef exports for RawList/VirtualList used a double `any` cast that dropped all prop type checking; switched them to the same typed-cast pattern already used by Listy/GroupHeader. --- src/RawList/index.tsx | 7 ++++++- src/RawList/useRawListScroll.ts | 4 ++-- src/VirtualList/index.tsx | 10 +++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/RawList/index.tsx b/src/RawList/index.tsx index e70b36d..facb150 100644 --- a/src/RawList/index.tsx +++ b/src/RawList/index.tsx @@ -132,6 +132,11 @@ function RawList( ); } -const RawListWithRef = React.forwardRef(RawList as any) as any; +const RawListWithRef = React.forwardRef(RawList) as < + T, + K extends React.Key = React.Key, +>( + props: RawListProps & { ref?: React.Ref }, +) => React.ReactElement; export default RawListWithRef; diff --git a/src/RawList/useRawListScroll.ts b/src/RawList/useRawListScroll.ts index b2463f4..af6ba93 100644 --- a/src/RawList/useRawListScroll.ts +++ b/src/RawList/useRawListScroll.ts @@ -1,5 +1,5 @@ import * as React from 'react'; -import type { ListyRef, PositionScrollToConfig, ScrollAlign } from '../List'; +import type { ListyRef, ScrollAlign } from '../List'; export default function useRawListScroll( ref: React.Ref, @@ -87,7 +87,7 @@ export default function useRawListScroll( return; } - const { left, top } = config as PositionScrollToConfig; + const { left, top } = config; if (left !== undefined) { holder.scrollLeft = left; } diff --git a/src/VirtualList/index.tsx b/src/VirtualList/index.tsx index dfa9eaa..bf46216 100644 --- a/src/VirtualList/index.tsx +++ b/src/VirtualList/index.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import clsx from 'clsx'; import RcVirtualList, { type ListRef as RcVirtualListRef, - type ScrollConfig, type ScrollOffsetInfo, } from '@rc-component/virtual-list'; import { useEvent } from '@rc-component/util'; @@ -122,7 +121,7 @@ function VirtualList( } // Other scroll shapes are already supported by the underlying virtual list. - listRef.current?.scrollTo(config as number | ScrollConfig | null); + listRef.current?.scrollTo(config); }); // ============================ Imperative ============================ @@ -197,6 +196,11 @@ function VirtualList( ); } -const VirtualListWithRef = React.forwardRef(VirtualList as any) as any; +const VirtualListWithRef = React.forwardRef(VirtualList) as < + T, + K extends React.Key = React.Key, +>( + props: VirtualListProps & { ref?: React.Ref }, +) => React.ReactElement; export default VirtualListWithRef; From 7a24e5effe1dfa65094f7ecca37340de3dd6aacc Mon Sep 17 00:00:00 2001 From: aojunhao123 <1844749591@qq.com> Date: Wed, 1 Jul 2026 23:51:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20keep=20scrollTo=20cast=20in=20Virtua?= =?UTF-8?q?lList=20=E2=80=94=20needed=20by=20father's=20pinned=20TS=205.4.?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pnpm compile failed: father resolves its own typescript@5.4.2 for declaration generation, independent of the root devDependency (typescript@6.0.3). TS 5.4.2 doesn't narrow the compound 'key' in config || 'groupKey' in config early-return as precisely as 6.x, so it still sees the full ListyScrollToConfig union at the scrollTo call and rejects it without the cast. --- src/VirtualList/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/VirtualList/index.tsx b/src/VirtualList/index.tsx index bf46216..e2cd833 100644 --- a/src/VirtualList/index.tsx +++ b/src/VirtualList/index.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import clsx from 'clsx'; import RcVirtualList, { type ListRef as RcVirtualListRef, + type ScrollConfig, type ScrollOffsetInfo, } from '@rc-component/virtual-list'; import { useEvent } from '@rc-component/util'; @@ -121,7 +122,7 @@ function VirtualList( } // Other scroll shapes are already supported by the underlying virtual list. - listRef.current?.scrollTo(config); + listRef.current?.scrollTo(config as number | ScrollConfig | null); }); // ============================ Imperative ============================