-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
discussionDiscuss idea or featureDiscuss idea or feature
Description
现在暂时只有List遇到了这个问题 由于List组件本身同时要支持拥有一个子组件+ref
所以需要由基本类型标注方法
React.FC<IComponentPropsType>
改为
React.FC<IComponentPropsType & React.RefAttributes<HTMLElement>> & { Item?: typeof ChildComponent }
此段类型为 React.FC<IComponentPropsType & React.RefAttributes<HTMLElement>> 用于标注React函数式组件类型
同时内部IComponentPropsType & React.RefAttributes<HTMLElement>为组件props类型 + 对应ref类型
后半段{ Item?: typeof ChildComponent }为对应子组件类型 如果遇到类似的操作可以考虑这种用法
但是同时子组件无法直接使用 因为此段子组件只能为可选属性 否则组件本身类型报错
此时有两种情况
- 如果使用解构
const { Item } = List;
const MenuItem = Item as typeof ListItem - 不使用解构
const Item = List.Item as typeof ListItem
暂时只有这种解决方案 如有更好方案欢迎在此issue下交流
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
discussionDiscuss idea or featureDiscuss idea or feature