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

oneOfType([Array, any()]) throws error at prop validation #140

Closed
victorgarciaesgi opened this issue Jul 13, 2021 · 5 comments · Fixed by #136
Closed

oneOfType([Array, any()]) throws error at prop validation #140

victorgarciaesgi opened this issue Jul 13, 2021 · 5 comments · Fixed by #136
Assignees
Labels

Comments

@victorgarciaesgi
Copy link
Collaborator

Hi it's me again! :D

I'm translating all my props to vue-types, and came accross a bug with oneOfType.

Before:

props: {
 value: { type: [Array, null] as PropType<any | any[]> }
}

So in vue-types:

props: {
 value: oneOfType([Array, any()])
}

And I got this errors :(

image

@victorgarciaesgi
Copy link
Collaborator Author

Ok found out that { type: [Array, null] as PropType<any | any[]> } produce the same error so not vue-types fault :p

@dwightjack
Copy link
Owner

@victorgarciaesgi no problem. I am not sure if it could help in your scenario, but there was a topic about nullable props some time ago (see #16).

Validations involving null are treated in a special way by Vue (if I remember well) and usually it's better to avoid them. So for example in your case PropType<any | any[]> translates, if I understand it correctly, to "any value is valid". It also depends n the version of Vue because some details have changed from v2 to v3. Which one are you using?

@dwightjack dwightjack reopened this Jul 13, 2021
@dwightjack dwightjack self-assigned this Jul 13, 2021
@victorgarciaesgi
Copy link
Collaborator Author

You're right that's exactly the same as putting any 😅 so it's my fault here!
Still on Vue 2 (Waiting for Nuxt 3 🙏)
It could be cool to cast to any() too, like putting any<AllPossibleValues>() or any<unknown>()

@dwightjack
Copy link
Owner

Just for reference, there's an open issue about nullable props in vue3 repo as well: vuejs/core#3948.

Looking at the source for props validation using null in an array of types (for example type: [Array, null]) might cause some validation errors.

About casting any, it seems a good idea. I'll take some time tomorrow to think about any side effect it might cause though.

@dwightjack
Copy link
Owner

I published v4.1.0 which should fix this issue.

Closing for now. Feel free to open a new issue if you experience any problems.

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

Successfully merging a pull request may close this issue.

2 participants