Subscribe on changes!

Proptype boolean | undefined typecasts to false if no default is set

avatar
Aug 4th 2022

Vue version

vue 3.2.37

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9UsFOwzAM/RWTy4a0NeJadUNIHDhy45JL2jldpzSJEpdpqvrvOC2DgQQXK/az33PyMoqnEIr3AUUpqtTELhAkpCGA1a7dKUFJib1yXR98JBghooEJTPQ9rHhsxZAjjEY3CK/RhwSjcgDG+8cSau8tapcLtY63hSnXlGu8SwRhntvBuaPjMxo9WErrA5rO4UxZzXG/vt9kckVMXsLglo4DSAmNjxEbshdoPaZvjIXub5U0q9AloDeLaMFUV6z+jfHKt7N9armD779evaC1Ht58tIe7FQtUcnk6fihOCPtgNSFnANXxIVdp3hrGkeM0X76SM3LtYB1iQe7g+EcHMKr/weofWCW/FhEbsRi47XUoTsk7tnv2SX0C7HK5OJdrbGzOlTgShVRKmUyTP8kpFT62kk9FHBx1PRaY+m0d/TlhZGIlMgVvMYnpAxwTzuQ=

Steps to reproduce

set an interface property value to possibly undefined and also boolean (can also be boolean | any) don't set a default value receive false instead of undefined

What is expected?

It should NOT typecast to false. This is not consistent with any other type

What is actually happening?

typecasts to false

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 AMD Ryzen 5 3600X 6-Core Processor
    Memory: 7.91 GB / 15.93 GB
  Binaries:
    Node: 16.14.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.15 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (103.0.1264.44)
    Internet Explorer: 11.0.22000.120

Any additional comments?

vue-tsc 0.37.9 Could also be a vue tsc issue

avatar
Aug 4th 2022
All props are optional by default, unless required: true is specified.

An absent optional prop other than Boolean will have undefined value.

The Boolean absent props will be cast to false. You should set a default value for it in order to get desired behavior.

Apparently it's in the docs, but regardless, it is a horrible feature. Undefined and false have literally nothing in common.