fix: support Partial values in setFieldsValue#782
fix: support Partial values in setFieldsValue#782QDyanbing wants to merge 1 commit intoreact-component:masterfrom
Conversation
|
@QDyanbing is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
总体介绍更新了 变更详情
代码审查工作量估计🎯 2 (Simple) | ⏱️ ~8 分钟 可能相关的 PR
建议的审查者
诗歌
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #782 +/- ##
=======================================
Coverage 99.54% 99.54%
=======================================
Files 20 20
Lines 1328 1328
Branches 325 325
=======================================
Hits 1322 1322
Misses 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/interface.ts (1)
283-283: 类型并集可行,建议补充注释说明意图对于具体的
Values类型,Partial<Values>在结构上已是RecursivePartial<Values>的子集,联合类型对已解析的具体类型并无额外收益。此改动的真正价值在于泛型转发场景(如测试中forwardGenericSetFieldsValue<Values>):当Values还是未解析的类型参数时,TS 无法证明Partial<Values>可赋值给RecursivePartial<Values>,因此需要显式加入Partial<Values>这条分支。建议在此处添加一行简短注释,避免后续维护者误以为该并集是冗余而移除它:
📝 建议补充注释
- setFieldsValue: (values: RecursivePartial<Values> | Partial<Values>) => void; + // `Partial<Values>` 分支用于在泛型包装场景下(Values 未解析时)保持可赋值性, + // 参见 tests/nameTypeCheck.test.tsx 中的 forwardGenericSetFieldsValue 用例。 + setFieldsValue: (values: RecursivePartial<Values> | Partial<Values>) => void;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/interface.ts` at line 283, Add a short explanatory comment above the setFieldsValue signature clarifying why the union type (RecursivePartial<Values> | Partial<Values>) is intentional: note that for concrete Values Partial<Values> is structurally a subset of RecursivePartial<Values>, but when Values is an unresolved type parameter (e.g., in generic forwarding helpers like forwardGenericSetFieldsValue<Values>) TypeScript cannot prove assignability, so the explicit Partial branch is required; reference the symbols setFieldsValue, RecursivePartial, Partial, Values and forwardGenericSetFieldsValue in the comment so future maintainers don't remove the union.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/interface.ts`:
- Line 283: Add a short explanatory comment above the setFieldsValue signature
clarifying why the union type (RecursivePartial<Values> | Partial<Values>) is
intentional: note that for concrete Values Partial<Values> is structurally a
subset of RecursivePartial<Values>, but when Values is an unresolved type
parameter (e.g., in generic forwarding helpers like
forwardGenericSetFieldsValue<Values>) TypeScript cannot prove assignability, so
the explicit Partial branch is required; reference the symbols setFieldsValue,
RecursivePartial, Partial, Values and forwardGenericSetFieldsValue in the
comment so future maintainers don't remove the union.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 421e9d4f-babc-4b78-b069-fa3cf720580f
📒 Files selected for processing (2)
src/interface.tstests/nameTypeCheck.test.tsx
There was a problem hiding this comment.
Code Review
This pull request updates the setFieldsValue method in the FormInstance interface to accept Partial<Values> in addition to RecursivePartial<Values>, facilitating the use of top-level generic partials. A corresponding test case was added to verify this behavior. I have no feedback to provide.
Summary
Partial<Values>insetFieldsValuealongside the existingRecursivePartial<Values>typingPartial<Values>intosetFieldsValueVerification
npm run lint:tscnpm test -- --runInBand tests/nameTypeCheck.test.tsxRefs ant-design/ant-design#57723
Summary by CodeRabbit
发布说明
改进
测试