-
Notifications
You must be signed in to change notification settings - Fork 344
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
Incorrect type determining required props #654
Comments
@scottbedard Looks like the approach is not correct, I am reverting it for now. About the problem, I think we have two different props, one for outer and one for inter while your problem looks like about outer props that pass into the component instead of the props for the setup function. Can you share a snippet about how you get this error? |
@antfu Ah, I did not realize that Here is a minimal reproduction |
Quick update here, it looks like we don't need to make any changes. I can get the type I need by using type ExtractPropTypesExternal<T, U = ExtractDefaultPropTypes<T>> = Partial<U>
& Omit<ExtractPropTypes<T>, keyof U>; |
I believe we have a bug with how we're determining required vs optional props...
composition-api/src/component/componentProps.ts
Lines 29 to 31 in be9de86
The second half of this condition looks backwards. We should be flagging props as required when they extend
{ default: never }
, not{ default: any }
. Having a default value means the prop isn't required, correct?To demonstrate the problem, create a component with the following prop...
Then attempt to render that component without defining
foo
.As you can see, our optional prop is incorrectly ending up on the required side of this intersection type.
It looks like this bug also exists in 3.x. If this is correct and I'm not misunderstanding how
default
should be effecting prop types, let me know and I'll open a PR there as well!https://github.com/vuejs/vue-next/blob/4a965802e883107a2af00301a59fb7f403b6acf7/packages/runtime-core/src/componentProps.ts#L70
The text was updated successfully, but these errors were encountered: