Typescript possible undefined loses type when using withDefaults and setting explicitly to undefined #6552
Labels
🍰 p2-nice-to-have
Priority 2: this is not breaking anything but nice to have it addressed.
scope: script-setup
Vue version
^3.2.37
Link to minimal reproduction
https://sfc.vuejs.org/#eNqNUbtuwzAM/BVCix0gsdHVsF0U7dCxH6DFdajEgfWARDcoAv97KSkJ0qXoYpg88u50vIgX56qvBUUj2jD6yREEpMXBPJhDJwUFKXppACbtrCe4eFQrKG81FLxWPECvVrsrUtWxiLxpQBpJozWBYIAOmKEshmIjTVtnSRbgglC7eSBMcm0k6NvEw422vqNiK7LgTg+uOgVr2PslyVwBttxA6sQem4i1FEciF5q6DmqMzk6hsv5Q81/lF0OTxgqD3n16ew7omViKSLFKs7Lk7T3/zmnkhYVw/zusyRB6NYwIH966kF0qa58bCOQnc2C1nFjOy6WpDs4THd9QDctModyjmgwmgjZ9+3KzvVM1sJg8sWcyTvnGFbO/uSrLDXQ90LdDq7JKxbt/3URSe3xKTwR4x3m2cLZ+Zg0+Vp2QxyOtP9U80FM=
Steps to reproduce
View the reproduction link, This does not show the full behavior, it requires a full IDE to view Simply copy and paste the few contents
undefined
What is expected?
Values that are set to be undefined, their types will continue to be possibly undefined, whereas others will not.
What is actually happening?
Values set explicitly to undefined will continue to be possibly undefined.
System Info
Any additional comments?
Issue taken from vuejs/language-tools#1672 ,
For some more information view this situation
As you can see, withDefaults basically infers that anything set into the withDefaults portion, is never going to be undefined. This works great for most situations, but in this situation, it must remain undefined, and not explicitly setting it to undefined causes Vue to use it in odd ways, (I believe Vue's default behavior will typecast a boolean to false when undefined. Which is why it needs to be explicitly set to undefined)
The text was updated successfully, but these errors were encountered: