Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types generated by ExtractPropTypes treat optional properties as required #5272

Closed
zouyaoji opened this issue Jan 17, 2022 · 5 comments
Closed

Comments

@zouyaoji
Copy link

Version

3.2.27

Reproduction link

codesandbox.io

Steps to reproduce

打开链接,鼠标放到第18行中的“b”变量上面。
Open the link, mouse over the "b" variable in line 18.

image

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


Similar to #3122

@yyx990803
Copy link
Member

yyx990803 commented Jan 17, 2022

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).

@zouyaoji
Copy link
Author

zouyaoji commented Jan 18, 2022

@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
Copy link
Member

I guess what you want is a separate ExtractExternalPropTypes?

@zouyaoji
Copy link
Author

Yes, I hope Vue can provide such a processing method.

@jd-solanki
Copy link

jd-solanki commented Apr 26, 2023

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants