vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.87k stars 400 forks source link

v-model with arguments and defineModel does not work for nullable types since 2.0.28 #4646

Closed davidglezz closed 3 months ago

davidglezz commented 3 months ago

Vue - Official extension or vue-tsc version

2.0.28 & 2.0.29

VSCode version

1.91.1

Vue version

3.4.35

TypeScript version

5.5.4

System Info

System:
    OS: macOS 14.4.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
    Memory: 43.05 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.0 - ~/.nvm/versions/node/v20.15.0/bin/node
    npm: 10.8.1 - ~/.nvm/versions/node/v20.15.0/bin/npm
    pnpm: 9.6.0 - ~/.nvm/versions/node/v20.15.0/bin/pnpm
    Watchman: 2024.04.01.00 - /usr/local/bin/watchman

Steps to reproduce

child.vue

const msg = defineModel('msg', {
  type: String as PropType<string | null>,
  default: null,
});

parent.vue

<template>
  <Child v-model:msg="msg" />
</template>
<script lang="ts" setup>
const msg = ref<string | null>('test');
</script>

Running vue-tsc or in vscode:

error TS2322: Type 'string | null' is not assignable to type 'string | undefined'.
163         v-model:msg="msg"

For default v-model looks like it works, but for v-model arguments it fail.

What is expected?

It should be correctly inferred as string | null and therefore not fail.

What is actually happening?

In 2.0.28 Error, in 2.0.26 No error

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-teuagl?file=src%2FApp.vue

No typecheck on stackblitz? :(

Any additional comments?

Thank you so much for this amazing and invaluable piece of software.