pro-components icon indicating copy to clipboard operation
pro-components copied to clipboard

🐛[BUG]ProForm.Item和ProForm.Group的类型错误

Open Aslan-Monster opened this issue 4 months ago • 1 comments

🐛 bug 描述

TS找不到组件的类型。查看ProForm类中的Item、Group组件类型的引用路径没找到

💻 复现代码

Image

© 版本信息

  • ProComponents 版本: [2.8.10]

Aslan-Monster avatar Aug 23 '25 06:08 Aslan-Monster

你遇到的 TS 类型找不到问题,是因为 ProForm.ItemProps 和 ProForm.GroupProps 这两个类型并没有被导出。实际上,ProForm.Item 和 ProForm.Group 是作为静态属性挂载在 ProForm 上的,但它们的 props 类型分别叫做 ProFormItemProps 和 ProFormGroupProps(有时也叫 GroupProps),需要单独导入,而不是通过 ProForm.ItemProps 或 ProForm.GroupProps 获取类型。

正确的用法如下:

import type { ProFormItemProps, ProFormGroupProps } from '@ant-design/pro-form';

// 用于 ProForm.Item
const itemProps: ProFormItemProps = { ... };

// 用于 ProForm.Group
const groupProps: ProFormGroupProps = { ... };

你不能这样写:

// ❌ 这样写类型是不存在的
type MyType = ProForm.ItemProps;

这是因为类型导出和组件静态属性的 API 设计没有做类型别名,属于常见的库设计模式问题,不是类型缺失或 bug。如果你需要类型提示,直接用 ProFormItemProps 和 ProFormGroupProps 即可。相关源码实现和类型导出方式可参考

如果你希望通过 ProForm.ItemProps 这种方式拿到类型,目前官方并没有这样导出,建议直接用上面的方法。

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

dosubot[bot] avatar Aug 23 '25 06:08 dosubot[bot]