Despite what the official VueJS 2 documentation on prop validation says in a code example comment:
// Basic type check (
null
andundefined
values will pass any type validation)
I encountered an error while testing this piece of code — could you explain why?
[Vue warn]: Invalid prop: type check failed for prop "value". Expected String, Number, Boolean, got Null
<template>
<div>
<h1>{{ title }}:</h1>
<MyInput :value="null" />
</div>
</template>
<script>
Vue.component('MyInput', Vue.extend({
props: {
value: {
type: [String, Number, Boolean],
required: true,
},
},
template: `
<select v-model="value">
<option value="null">
null value
</option>
<option value="">
Empty value
</option>
</select>`,
}));
export default {
data: () => ({
title: 'Why is VueJS Prop Type Validation Failing with NULL and `undefined` Values?'
}),
};
</script>