type Validator = (value: any, key: string, props: Object, warn: (message: string) => void) => boolean
Example:
export default {
props: {
foo: {
validator(value, key, props, warn) {
if ('bar' in props && 'foo' in props) warn('Foo and Bar cannot be used together.')
return true
}
....
Should not the warn function be returned to stop the rest of the validator code from executing?
I'm a fan of adding the prop as an argument. I think we can return a string from the validator function and let Vue treat that as an error.
My counter proposal is
type ValidatorOutput = boolean | string
type Validator = (value: any, key: string, props: Object) => ValidatorOutput
Closing in favor of #9467. Also, I think changing arguments of prop validator function would require an RFC now.
For a global workaround, see https://github.com/vuejs/vue/issues/9467#issuecomment-465708425
Most helpful comment
I'm a fan of adding the prop as an argument. I think we can return a string from the validator function and let Vue treat that as an error.
My counter proposal is