-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
How to use validator in using interface declaration props in Vue3 #8152
Comments
interface Props {
propF?: 'success' | 'warning' | 'danger';
} |
|
He may want to use the interface to validate props. |
@Alfred-Skyblue |
deafult values are also runtime only, but it's possible to set them when you're using ts version of defineProps |
It seems that this problem can be described as:
• Requirement: The user expects to use defineProps with a type declaration, but in some scenarios, he hopes to use the validator to validate the prop values more flexibly (the scenario I can think of is that the component library is written in TS and published to npm, when the user introduces the component in js, if a value outside the expected range is passed in, it is hoped to print more detailed and friendly error logs to prompt the user). |
I am currently unclear if there is a way to achieve your requirements,
|
verifying simple types is okay, but more complex verifications should not be enough |
@wht300 Not possible with vue's compiler, but possible with https://github.com/so1ve/unplugin-vue-complex-types :D |
I'm closing this issue because it's more like a question than a feature request. For now, I think https://github.com/unplugin/unplugin-vue-complex-types is already a good experimental solution for this issue. |
What problem does this feature solve?
As is well known, using
validator
in Optional APIs, for example:so,how to use
validator
in Composition ApiWhat does the proposed API look like?
I am not sure if there is a ready-made solution. If so, please @ me. If not, my suggestion is to provide a method similar to withDefault, such as withValidator
The text was updated successfully, but these errors were encountered: