fix: remove unnecessary/unsafe type assertions in RawList and VirtualList#53
Conversation
…List 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.
|
@aojunhao123 is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
Walkthrough本次改动将 Changes类型精确化
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR tightens TypeScript typing around list scrolling and forwardRef exports by removing redundant/unsafe type assertions and replacing any-based forwardRef casts with the project’s established typed generic pattern.
Changes:
- Removed unnecessary
asassertions around scroll config handling inVirtualListanduseRawListScroll. - Replaced
React.forwardRef(X as any) as anywith a typed genericforwardRefcast pattern forRawListWithRefandVirtualListWithRef.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/VirtualList/index.tsx | Removes redundant scrollTo type assertion and replaces any-based forwardRef export with typed generic pattern. |
| src/RawList/useRawListScroll.ts | Removes redundant cast/import by relying on control-flow narrowing for position scroll config. |
| src/RawList/index.tsx | Replaces any-based forwardRef export with typed generic pattern consistent with the codebase. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request improves TypeScript type safety across the RawList and VirtualList components. It replaces loose 'any' type assertions on React.forwardRef with strongly-typed generic signatures. Additionally, it cleans up unused type imports and removes unnecessary type assertions when handling scroll configurations. I have no further feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
… 5.4.2 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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #53 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 211 211
Branches 62 63 +1
=========================================
Hits 211 211 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Summary
React.forwardRef(X as any) as anydouble-cast used forRawListWithRef/VirtualListWithRefwith the same typed-cast pattern already used byListy/GroupHeaderin this codebase, restoring prop type checking on those exports.as PositionScrollToConfigcast inuseRawListScroll— control-flow narrowing already produces the correct type there (verified against both the roottypescript@6.0.3and father's internally-pinnedtypescript@5.4.2).item[rowKey] as React.Keycasts in place —Tis a fully generic type parameter, so a conditional/mapped type can't narrowT[keyof T]toReact.Keyfor an abstractT(confirmed by attempting aKeysMatching<T, React.Key>restriction onRowKey<T>, whichtscrejects). This is a real boundary of the type system, not an oversight.config as number | ScrollConfig | nullcast inVirtualList'sscrollToin place too. It initially looked removable under the roottypescript@6.0.3, butpnpm compilefailed: father resolves its owntypescript@5.4.2for declaration generation, and that version doesn't narrow the'key' in config || 'groupKey' in configearly-return pattern precisely enough to dropGroupScrollToConfigfrom the union, so it still needs the cast.Test plan
npx tsc --noEmit -p tsconfig.json(typescript@6.0.3)typescript@5.4.2via directtsc --noEmit -p tsconfig.jsonpnpm compile(father build + declaration generation)npx eslint src/ --ext .tsx,.tsnpx rc-test(4 suites, 40 tests, all passing)