Add enum sugar for prop validators
See original GitHub issueWhat problem does this feature solve?
For enum props, it’s common to validate the given value against valid enum values like this:
props: {
position: {
type: String,
validator (val) {
return ['top', 'right', 'bottom', 'left'].includes(val)
}
}
}
What does the proposed API look like?
I think it’ll be handy to provide extra convenience by supporting this:
props: {
position: {
type: String,
validator: ['top', 'right', 'bottom', 'left']
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:34
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Validations for Enum Types - Baeldung
Learn how to build validations for enums using Java custom annotations.
Read more >How to Validate Your Data with Custom Validators of Pydantic ...
In practice, this type of simple validation can be achieved with an Enum or a literal type. However, let's focus on the basic...
Read more >How can I guarantee that my enums definition doesn't change ...
For each entry, create a new local variable whose name starts with ENUM_ or INDEX_ , then the name of the group, then...
Read more >JavaScript Enums - Mastering JS
JavaScript Enums · Get all allowed enum values: Object.keys(Direction) returns an array ['Up', 'Down', 'Left', 'Right'] · You can modify the enum ......
Read more >Enum: Not Just a Constant With a Pretty Face - kdgregory.com
The enum keyword was introduced with JDK 1.5 (Java 5), as syntactic sugar for creating a subclass of java.lang.Enum and adding static ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
if you want a shorthand, just use an arrow function:
Less magic. It’s Just JavaScript.
If the goal is
enum
, maybe we should be explicit about it?It would only checks exact matches against the passed array. In example from graphQL https://graphql.org/learn/schema/#enumeration-types . From the docs it states two of the benefits.
I think in this case, both apply to Vue, no?