vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.36k stars 8.28k forks source link

nullable boolean props not getting `undefined` union #12098

Open iammola opened 2 weeks ago

iammola commented 2 weeks ago

Vue version

3.5.10

Link to minimal reproduction

https://play.vuejs.org/#eNp9UsFOAjEQ/ZVJL2pC4CAnsmDUcMADEvXYA8vuAMVup9nO4hrcf3e6K4iJ4daZ9/rem2kP6t77/r5CNVJJyErjGQJy5cGmbjPWioNWE+0ycoHhACsii6lblOShgTHkuDYOYxmSP+jd6FjBF1Su4+XQTK5vtEsGnZUIS8FYeJsySgWQbIeTObHJEHiLsDyTXIKPtiYAf3rRSgOIOtbemszwibrsw4whJwzuimGb7kWJYIWRTJ4NudS2Sj3YVTJUoOgLrV1GOUaDjApvLObJQOLEvGcZVU+WIvtYm01/F8jJ5g5RQaufW+Vz6yKLG0GLRCy1lj6e2h6XFfaO/WyL2fs//V2oY0+rRYkByz1qdcI4LTfIHTx9nWMt5xNYUF5ZYV8AXzCQrWLGjvYg7yOxz3ht2lnhqWTjNm9hWjO6cBwqBo3MpuVrJd/n8cLov3Fv+8P2nnaNar4BQJzWTg==

Steps to reproduce

Create a boolean or undefined prop using the defineProps macro.

What is expected?

For the inferred prop type to have undefined as a possible type

What is actually happening?

It strips out the undefined type, leaving only boolean.

System Info

No response

Any additional comments?

I believe it's in https://github.com/vuejs/core/blob/29de6f8b0bb1a604f247b0712daac29e93aa6f3e/packages/runtime-core/src/apiSetupHelpers.ts#L96-L98

Should be fixed by using the original type

export type DefineProps<T, BKeys extends keyof T> = Readonly<T> & { 
  readonly [K in BKeys]-?: T[K]
} 
edison1105 commented 22 hours ago

This is the expected behavior. A boolean prop cannot be undefined in Vue, it will always be cast to false at runtime. so the types should reflect that.