Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not alllow null for optional props #4868

Open
rchl opened this issue Sep 23, 2024 · 2 comments
Open

Does not alllow null for optional props #4868

rchl opened this issue Sep 23, 2024 · 2 comments
Labels

Comments

@rchl
Copy link
Collaborator

rchl commented Sep 23, 2024

Vue - Official extension or vue-tsc version

2.1.6

VSCode version

1.93.1

Vue version

3.5.8

TypeScript version

5.6.2

System Info

System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 6.20 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
    Yarn: 1.22.22 - ~/.yarn/bin/yarn
    npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
    pnpm: 9.9.0 - ~/.nvm/versions/node/v20.16.0/bin/pnpm
  Browsers:
    Chrome: 129.0.6668.59
    Safari: 18.0
    Safari Technology Preview: 18.0

package.json dependencies

"dependencies": {
    "vue": "^3.5.6"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^5.1.3",
    "typescript": "^5.5.3",
    "vite": "^5.4.6",
    "vue-tsc": "^2.1.6"
  }

Steps to reproduce

  1. Create component with optional String props:
  props: {
    msg: {
      type: String,
      default: null,
    },
  },
  1. Pass null to msg prop from the parent component:
<HelloWorld :msg="null" />

What is expected?

No type error

What is actually happening?

src/App.vue:9:16 - error TS2322: Type 'null' is not assignable to type 'string | undefined'.

9   <HelloWorld :msg="null" />

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-3fqeyw?file=tsconfig.json,src%2FApp.vue,src%2Fcomponents%2FHelloWorld.vue,package.json&terminal=dev

Any additional comments?

I'm not sure why is null not allowed. Vue doesn't complain when being passed either undefined or null (see attached reproduction).

Note: regardless whether null or undefined is passed, Vue sets the value to null within the component.

@KazariEX
Copy link
Collaborator

It should be a https://github.com/vuejs/core issue.

@rchl
Copy link
Collaborator Author

rchl commented Sep 23, 2024

Actually it appears that I've created such issue there before: vuejs/core#8600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants