Skip to content

Optional boolean prop gives type Ref<boolean | undefined> which should be Ref<boolean> #7487

Closed
@jd-solanki

Description

@jd-solanki

Vue version

3.2.45

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9kN1qwzAMhV9F+KYbNDa7DW7H2AvsAXyTpkqTEv8gOy0j+N0npz9sHfTO50j6ZJ1ZfIQgTxOKWujY0hASRExT2Bo32OApwQyEHWToyFtYcevqXvr0Nlx9qYooJC5rdUExhEVCG8YmISsAvcwofmt1L4i1uBAr2wR5jN7xd+bSbq6FaEQNi1M83lK0EX1KIdZKxa4tq49RejoofkmaXBosSoy22pE/RyQGG7H+xVBsnpAqQrdHQnrGfGj9xy3YbFzmU25BPEYKY+MOGyPKMXx/611MEMiHCBvYYzc4/CpKL3fG3p/fa9h5P2LDMebty+vzZPu37Twvc5AzVMAifQf03c3Tilv+Bp9/APuhswM=

Steps to reproduce

Here, we get show type as Ref<boolean> however in VS Code it is Ref<boolean | undefined> 🤔

image

  1. check the type of the boolean in autosuggestion as shown in image

What is expected?

It should have property type as Ref according to this: https://vuejs.org/guide/components/props.html#prop-validation

The Boolean absent props will be cast to false. You can change this by setting a default for it — i.e.: default: undefined to behave as a non-Boolean prop.

What is actually happening?

It is getting type as Ref<boolean|undefined> where undefined is invalid.

System Info

System:
    OS: macOS 12.5.1
    CPU: (8) arm64 Apple M1
    Memory: 101.03 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.16.0/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
  Browsers:
    Chrome: 105.0.5195.102
    Safari: 15.6.1
  npmPackages:
    vue: 3.2.45 => 3.2.45

Any additional comments?

Original Issue: vuejs/language-tools#2219

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions