Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Make runtime Props validation optional #548

Closed
rdhelms opened this issue Mar 5, 2023 · 5 comments
Closed

Make runtime Props validation optional #548

rdhelms opened this issue Mar 5, 2023 · 5 comments

Comments

@rdhelms
Copy link

rdhelms commented Mar 5, 2023

What problem does this feature solve?

Now that Vue is embracing TS, I think there’s much less value in validating component props via JS prototypes at runtime. It can still be a useful feature for a pure JS setup, but if someone has a TS setup where Volar is able to see the types without a runtime definition, they really don’t need the type to be validated at runtime.

Validating component props at runtime feels like trying to validate function params at runtime. It seems better to just let TS handle it.

What does the proposed API look like?

The goal would be for the app not to throw a runtime error for a setup such as in vuejs/core#7832, and instead allow the prop to pass through to the child component.

Perhaps this could be controlled with a validateRuntimeProps boolean option in vite.config.

@rdhelms
Copy link
Author

rdhelms commented Mar 7, 2023

@sxzz I'm honored by the 👍! 🙏 I'm curious if you have any other context or info to add here? Additional use cases or thoughts on the potential value? I'd love to get some traction here because we're looking to migrate hundreds of components to Vue 3 and this feature would impact how we decide to do that.

@sxzz
Copy link
Member

sxzz commented Mar 7, 2023

I like this proposal! It's worth mentioning that runtime type validation is on dev only. I also think now we're using TypeScript in development, the runtime type validation seems to be unnecessary. So there should be an option to disable this feature, just like Options API.

However, Vue still needs some type (like Boolean or Function), which will affect the runtime behavior. For example, if the prop has Boolean type, Vue will convert undefined to false in runtime.

@rdhelms
Copy link
Author

rdhelms commented Mar 10, 2023

@sxzz When you say "just like the Options API", do you mean that there's currently a way to opt out of props validation using the Options API?

@sxzz
Copy link
Member

sxzz commented Mar 10, 2023

I mean we can add a bundler build feature flag, to disable props validation, just like __VUE_OPTIONS_API__ for Options API.

https://github.com/vuejs/core/blob/main/packages/vue/README.md#bundler-build-feature-flags

@GrantGryczan
Copy link

GrantGryczan commented Aug 31, 2023

I need this because otherwise I can't use complex TypeScript types for my props (such as an intersection with a base component's exported prop interface), due to Vue being unable to convert them to runtime validators. Which is a pointless limitation when I don't even need runtime validators.

In fact, personally I would disable runtime prop validation by default when using the TypeScript form of defineProps. I might even make a separate issue for that suggestion since it could be accepted independently of this.

Edit: #547

@haoqunjiang haoqunjiang transferred this issue from vuejs/core Sep 1, 2023
@vuejs vuejs locked and limited conversation to collaborators Sep 1, 2023
@haoqunjiang haoqunjiang converted this issue into discussion #549 Sep 1, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants