fix(type): accept partial generic form values#790
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough改进了类型别名 Changes类型与测试改动
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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#setFieldsValuetyping to acceptPartial<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. Preferunknownand 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.
Summary by CodeRabbit
发布说明
Refactor
RecursivePartial行为:对 Date/RegExp/Function/Map/Set 等保持原类型,不再递归展开。setFieldsValue签名,支持传入浅层 Partial 值或递归 Partial。Tests
Chores