Skip to content

fix: support Partial values in setFieldsValue#782

Open
QDyanbing wants to merge 1 commit intoreact-component:masterfrom
QDyanbing:fix/set-fields-value-generic-partial
Open

fix: support Partial values in setFieldsValue#782
QDyanbing wants to merge 1 commit intoreact-component:masterfrom
QDyanbing:fix/set-fields-value-generic-partial

Conversation

@QDyanbing
Copy link
Copy Markdown
Contributor

@QDyanbing QDyanbing commented Apr 21, 2026

Summary

  • accept Partial<Values> in setFieldsValue alongside the existing RecursivePartial<Values> typing
  • preserve the current recursive partial behavior for nested field updates
  • add type regression coverage for generic wrappers that forward Partial<Values> into setFieldsValue

Verification

  • npm run lint:tsc
  • npm test -- --runInBand tests/nameTypeCheck.test.tsx

Refs ant-design/ant-design#57723

Summary by CodeRabbit

发布说明

  • 改进

    • 增强表单字段值设置方法的参数灵活性,现支持更多参数类型。
  • 测试

    • 新增类型检查测试用例。

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 21, 2026

@QDyanbing is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

总体介绍

更新了 FormInstance<Values> 的公开方法 setFieldsValue 的签名,使其接受完全递归的 RecursivePartial<Values> 或浅层 Partial<Values>。接口中的其他声明和控制流保持不变。

变更详情

文件分组 / 文件 变更摘要
类型签名更新
src/interface.ts
setFieldsValue 方法参数类型从 RecursivePartial<Values> 扩展为 RecursivePartial<Values> | Partial<Values> 以支持更灵活的值传递方式。
测试辅助函数
tests/nameTypeCheck.test.tsx
添加通用辅助函数 forwardGenericSetFieldsValue 验证新的浅层类型签名兼容性。

代码审查工作量估计

🎯 2 (Simple) | ⏱️ ~8 分钟

可能相关的 PR

建议的审查者

  • zombieJ

诗歌

🐰 ✨
类型的边界又放宽了,
递归与浅层共舞,
表单字段更自在,
小兔欢呼又一步!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:为setFieldsValue方法添加了对Partial值的支持,这正是PR的核心目的。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.54%. Comparing base (f08c1cc) to head (52e3764).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between f08c1cc and 52e3764.

📒 Files selected for processing (2)
  • src/interface.ts
  • tests/nameTypeCheck.test.tsx

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant