Skip to content

fix(type): accept partial generic form values#790

Open
li-jia-nan wants to merge 2 commits into
masterfrom
RecursivePartial-type
Open

fix(type): accept partial generic form values#790
li-jia-nan wants to merge 2 commits into
masterfrom
RecursivePartial-type

Conversation

@li-jia-nan

@li-jia-nan li-jia-nan commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

发布说明

  • Refactor

    • 优化通用类型 RecursivePartial 行为:对 Date/RegExp/Function/Map/Set 等保持原类型,不再递归展开。
    • 扩展表单方法 setFieldsValue 签名,支持传入浅层 Partial 值或递归 Partial。
  • Tests

    • 调整并新增测试用例以覆盖浅层 Partial 接收与断言行为。
  • Chores

    • 增强 TypeScript 类型标注以满足编译器约束(捕获异常类型显式标注)。

@vercel

vercel Bot commented Jun 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
field-form Error Error Jun 13, 2026 7:26pm

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7d442aff-fe57-49af-8284-2623dbd6ec38

📥 Commits

Reviewing files that changed from the base of the PR and between ab7f392 and 8ccab75.

📒 Files selected for processing (2)
  • src/interface.ts
  • tests/index.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/interface.ts

Walkthrough

改进了类型别名 RecursivePartial<T> 的终止分支,扩展 FormInstance.setFieldsValue 签名以接受 RecursivePartial<Values> | Partial<Values>,并更新/新增测试以配合类型变化;同时为 validateUtil 的异常捕获添加了 any 注解。

Changes

类型与测试改动

Layer / File(s) Summary
RecursivePartial 改进与 setFieldsValue 签名扩展
src/interface.ts
RecursivePartial<T>Date, RegExp, Function, Map, Set 添加终止分支;FormInstance.setFieldsValue 参数类型从 RecursivePartial<Values> 扩展为 RecursivePartial<Values> | Partial<Values>
关联测试更新与新增用例
tests/index.test.tsx
将断言 not.toThrowError()not.toThrow(),将 refForm 改为可空并使用 refForm?.setFieldsValue(...);新增用例 accepts partial values from generic helper 验证接受 Partial<Values>
异常捕获类型标注
src/utils/validateUtil.ts
catch (errObj) 添加显式类型 catch (errObj: any)
  • Estimated code review effort: 🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Possibly related PRs:

  • Suggested reviewers:

    • zombieJ
    • yoyo837
  • Poem:

兔子敲键改类型,递归在边界止步,
setFieldsValue 张开怀抱,Partial 来做客,
测试轻敲确认声,异常注释道一声:any,
类型和谐代码欢笑,春风拂过代码园。 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题清晰地概括了主要变更:修复类型定义以接受部分泛型表单值,与改动内容直接相关。
Linked Issues check ✅ Passed 代码变更完全满足issue #57723的要求:增强RecursivePartial类型处理,扩展setFieldsValue签名接受Partial,解决类型检查不通过的问题。
Out of Scope Changes check ✅ Passed 所有变更均与解决issue #57723的TypeScript类型兼容性问题直接相关,包括类型定义、方法签名和测试用例调整,无超范围改动。

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch RecursivePartial-type

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.54%. Comparing base (a6cfe2e) to head (8ccab75).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #790   +/-   ##
=======================================
  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 Harness.
📢 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.

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

Copy link
Copy Markdown

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 RecursivePartial utility type in src/interface.ts to exclude built-in types like Date, RegExp, Function, Map, and Set from being deeply partialized, and updates setFieldsValue to accept RecursivePartial<Values> | Partial<Values>. In src/utils/validateUtil.ts, the catch block parameter errObj is explicitly typed as any. Feedback suggests using optional chaining (errObj?.errors) to prevent potential runtime TypeError crashes if errObj is null or undefined.

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.

Comment thread src/utils/validateUtil.ts
Copilot AI review requested due to automatic review settings June 13, 2026 19:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the form typings to accept partial generic value objects when calling setFieldsValue, addressing ant-design/ant-design#57723 and improving compatibility with common generic helper patterns.

Changes:

  • Expand FormInstance#setFieldsValue typing to accept Partial<Values> in addition to the existing recursive partial type.
  • Refine RecursivePartial<T> to treat special/atomic types (e.g., Date, RegExp, Function, Map, Set) as non-recursive.
  • Add/adjust tests to ensure the updated typing composes cleanly with a generic setter helper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/index.test.tsx Updates assertions and adds a compile-time-oriented test case for generic partial setters.
src/utils/validateUtil.ts Adjusts catch variable typing in async validator error handling.
src/interface.ts Updates RecursivePartial and widens setFieldsValue parameter type to also accept Partial<Values>.
Comments suppressed due to low confidence (1)

src/utils/validateUtil.ts:90

  • Avoid typing the caught error as any; it weakens type-safety across this block. Prefer unknown and locally narrow/cast to the shape you need (e.g., { errors?: ... }) before accessing .errors.
  try {
    await Promise.resolve(validator.validate({ [name]: value }, { ...options }));
  } catch (errObj: any) {
    if (errObj.errors) {
      result = errObj.errors.map(({ message }, index: number) => {
        const mergedMessage = message === CODE_LOGIC_ERROR ? messages.default : message;

        return React.isValidElement(mergedMessage)
          ? // Wrap ReactNode with `key`
            React.cloneElement(mergedMessage, { key: `error_${index}` })
          : mergedMessage;
      });
    }
  }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/index.test.tsx
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.

6.3.6 版本下, form.setFieldsValue 参数类型校验问题

2 participants