Subscribe on changes!

Component props default value/type error

avatar
Jan 3rd 2023

Vue version

latest

Link to minimal reproduction

https://sfc.vuejs.org/#eNrlVUuPmzAQ/itTLqRSAtpLVVESabuXHlfqoYe6BxKchBXYlj2hWVH+e8cPCEn21b02l+CZb57fZ+iiW6WS9sCjLMrNRlcKwXA8qBUTVaOkRuhA8+1c82KDVcuhh62WDcQUE4+Y+0JzgcGTpP5o0xKEiY0UBqExO1jaXLP4G69rCT+krssP8ccTZCt14zC+1qxjAgC5wQxiytQTNE99l9QfHZA3qi6Q0wkg39+sus7V6fs8pZOzVkIdENpFI0teL1lEfhY5l3OH1jNbm7z2j0WQEiBPx/TRPPKTLppCJQ9GCtqX644Fh2FRBs5ibTS5PbNoj6hMlqZmu7HreDCJ1LuUnhJ9EFg1POGmWay1/G24psQsmk9ypGRsuV5QhyXXXL+U8wJ6ldem7WmHNMqJngnrdSF2yxhNfMn/3b6qy5FadwrMTgG3QuKe63NcMAa451hpqQyRXPJtJfi9PeVub3bzboUMGXrSDepK7IbOV7NRKrLmSS13M5cssZFziJVn0oZaUT2NS6z7GvysrBjmZdV6ubhH2NSFMaSUtTwGHdnfiPI/v7Q7SRsSto6bc8SmU/Bo9TEkRBl06HolMWbrQl+YrD4vU/1jdwNjb2+SYWhyCH1vr8PT5Ia5vRt8rDmYjVS8dMCExgiXai01CTuDG3UE4rUqv3i7KsqSRJJ9VsdgaQq9q8QCpcpuPgUr6YcotuntXR5F/KL+X9WrHBQKf6g90lpBQzCkDWTDmTyDiL1+3yK0S76oEuCj4nQ7Ovcgt87W01QBkq/1uOcQ0Rb1wYd4bBDamWL2p6jzkjTDVUlre76k9Z5KeuxVySeIH+iYvCvex4r/WjhWgmT8AD+/OwLm8NVT8svpwb1mHVPn4ACag4/y4Fc+PWfU/Vfc9X8Bc0+1bg==

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.

avatar
Jan 3rd 2023

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

avatar
Mar 20th 2023

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