language-tools: Incorrect TS issues being reported after upgrade to 2.2.6

Vue - Official extension or vue-tsc version

2.2.6

VSCode version

1.97.2

Vue version

3.5.13

TypeScript version

5.7.3

System Info


package.json dependencies


Steps to reproduce

Create a SFC with a v-model that accepts different types, such as:

const model = defineModel<string | number>({
    required: true,
});

Then use the component:

const testValue = ref("Hello, World")
<MyComponent v-model="testValue" />

What is expected?

Given the following is valid TS:

let test:string | number = "test"
test = 8;

There should be no TypeScript errors.

What is actually happening?

The following error is being displayed in VSCode:

Type 'string | number' is not assignable to type 'string'.
  Type 'number' is not assignable to type 'string'. ts-plugin(2322)

Link to minimal reproduction

https://github.com/richmason/vue-ts-issue

Any additional comments?

This was not an issue in version 2.2.4

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Please update to v2.2.8.

It seems difficult to implement complete type checking in these upstream component libraries😅We should make this feature default to false and opt-in.

So why don’t you write like:

<script setup lang="ts" generic="T extends string | number">
defineModel<T>();
</script>

?

This is expected behavior, since v-model is two way bindings. It requires that the variable passed in is strictly consistent with the type of model value.

But, why? Parent component model value is string, why could the update event become string | number only because the child component supports number? Shouldn’t it be consistent with the model value’s type string?

This change seems causes a huge amount of v-model type errors.