Component props default value/type error
Vue version
latest
Link to minimal reproduction
Steps to reproduce
In order to restore my case more realistically, I created one more file, maybe it is not a minimal copy, sorry.
I defined the child component with type boolean
or string
, and i use it in initial. I found that it wasn't using the value I passed in when I initialized.
I guess this playground can explain everything, hope it is meaning enough.
What is expected?
Although I pass in an empty string when initializing, i want subcomponet use the porps value from parent continue. Instead of subcomponents transforming themselves.
What is actually happening?
I don't quite understand why it converts the value by itself. It seems to be related to the order of the prop types written.
System Info
No response
Any additional comments?
I don't know if there is a related issue in this case, please forgive me for not looking for similar cases and reporting directly.
I think this may be a bug. During the normalization process of props, when the type is boolean or string, the incoming value of the string type will be prioritized as a boolean type for normalization
It is indeed a bug that violates the documented behavior, but in the opposite way than you might have expected:
When a prop is declared to allow multiple types, e.g.
export default { props: { disabled: [Boolean, Number] } }
The casting rules for Boolean will apply regardless of type appearance order.
https://vuejs.org/guide/components/props.html#boolean-casting