Skip to content

fix: preserve null unions in setFieldsValue types#781

Merged
zombieJ merged 1 commit intoreact-component:masterfrom
QDyanbing:fix/set-fields-value-null-array-union
Apr 19, 2026
Merged

fix: preserve null unions in setFieldsValue types#781
zombieJ merged 1 commit intoreact-component:masterfrom
QDyanbing:fix/set-fields-value-null-array-union

Conversation

@QDyanbing
Copy link
Copy Markdown
Contributor

@QDyanbing QDyanbing commented Apr 18, 2026

变更说明

  • 修复 RecursivePartialnull 联合类型的错误收窄,使 setFieldsValue 能正确接受 数组 | null 类型的字段
  • 保留历史上的类型行为,确保可选父字段下的递归 partial 能力不受影响
  • 补充类型回归测试,覆盖 null 联合场景以及之前可选嵌套字段的 partial 场景

验证

  • npm run lint:tsc

fix ant-design/ant-design#57707

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 18, 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 18, 2026

总体概述

此PR修改了 RecursivePartial<T> 类型的实现逻辑,简化了对数组和对象的递归偏选处理,同时扩展了相关的编译时类型检查测试覆盖范围。

改动一览

类型/文件(s) 改动摘要
类型定义重构
src/interface.ts
修改了 RecursivePartial<T> 的类型检查逻辑:移除了 NonNullable<T> 的中间层处理,直接检查数组和对象类型,通过 RecursivePartial<U>[] 处理数组元素,对象属性值进行递归偏选。
编译时类型检查扩展
tests/nameTypeCheck.test.tsx
添加了 FormInstance 导入,扩展了 FieldType 类型定义(新增 strictListusernullableListnullableObjectList 等字段),引入 SetFieldsValueParam 类型及多个覆盖空值、数组和嵌套对象等场景的常量。

代码审查估计

🎯 3 (中等) | ⏱️ ~20 分钟

建议审查者

  • zombieJ

兔兔之歌

🐰 类型的魔法更精妙,
递归层次更简洁,
数组对象无烦恼,
测试覆盖添新彩,
TypeScript的世界真美妙! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确反映了本次变更的核心目标,即在setFieldsValue类型中保留null联合类型,使其能够接受数组或null类型的字段。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.54%. Comparing base (713c103) to head (570c0b6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #781   +/-   ##
=======================================
  Coverage   99.54%   99.54%           
=======================================
  Files          20       20           
  Lines        1328     1328           
  Branches      329      329           
=======================================
  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

@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 refactors the RecursivePartial utility type to simplify its structure and adds comprehensive test cases for nullable lists and nested optional objects. A suggestion was made to update the array check to support readonly types, preventing immutable arrays from being incorrectly processed as objects.

Comment thread src/interface.ts
@zombieJ zombieJ merged commit eb43999 into react-component:master Apr 19, 2026
7 of 8 checks passed
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.

setFieldsValue 数组和null联合类型指定null值会提示类型错误

2 participants