Types generated by ExtractPropTypes treat optional properties as required
Version
3.2.27
Reproduction link
Steps to reproduce
打开链接,鼠标放到第18行中的“b”变量上面。 Open the link, mouse over the "b" variable in line 18.
What is expected?
不要将required属性为false的属性标记为必选属性 Don't mark a property with the required property false as required
What is actually happening?
将可选prop标记成了必选 Treat optional properties as required
ExtractPropsTypes
's return type is the type of the internal normalized props (i.e. what the child component sees), not the expected external props (i.e. what the parent component is passing).
@yyx990803
It is still recommended to consider it. If it can be done, the component does not need to maintain the type definition of the component itself, and it can be extracted directly with ExtractPropsTypes. 还是建议考虑一下呢,如果能做到的话,组件库就不用自己维护组件的类型定义了,直接用ExtractPropsTypes展开导出就行。
Should this be considered a new requirement? 或许这应该算一个新需求?
I may not have made my real needs clear. For more discussion on this need, see here 我可能没要讲清楚我的真实需求,关于这个需求更多讨论的可以看这里
@yyx990803 I heavily use ExtractPropTypes
in my UI lib and later found that I'm facing the similar issue as mentioned.
As we are already working on type improvements for vue 3.3, adding ExtractExternalPropTypes
or something similar will make props & it's type reusability much more ease.
Here's how I reuse props: https://github.com/jd-solanki/anu/blob/main/packages/anu-vue/src/components/card/props.ts#L6-L29
If possible can you please reopen the issue or should I create new issue for tracking this feature request?
Regards.