-
-
Notifications
You must be signed in to change notification settings - Fork 438
Incorrect TS issues being reported after upgrade to 2.2.6 #5227
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
Comments
The issue was introduced in I also had a reproduction for this https://stackblitz.com/edit/vitejs-vite-zgqorhob?file=src%2Fcomponents%2Fcomp.vue |
This is expected behavior, since |
But, why? Parent component model value is This change seems causes a huge amount of v-model type errors. |
Though there are cases that for reusability we'd like to accept two types or more, this restriction is messing with so many uses |
@KazariEX <script setup lang="ts" generic="T extends string | number">
const props = defineProps<{
modelValue: T
}>()
const emit = defineEmits<{
'update:modelValue': [value: T]
}>()
</script> rather than <script setup lang="ts">
const props = defineProps<{
modelValue: string | number
}>()
const emit = defineEmits<{
'update:modelValue': [value: string | number]
}>()
</script> |
So why don't you write like: <script setup lang="ts" generic="T extends string | number">
defineModel<T>();
</script> ? |
Because many components(also from library) write |
You can report those issues to the upstream libraries and pin the version at v2.2.4. Anyway, the current behavior is inevitably brought through the implementation of two way bindings of types. |
It seems difficult to implement complete type checking in these upstream component libraries😅We should make this feature default to false and opt-in. |
it would be nice if there can be an option to not opt-in this feature, there're just too many errors after upgraded to Can understand the requirement of type checking on two way bindings. But it's pretty tricky actually. Most of time, for example, there's a component has v-model supporting |
In the case you mentioned generics are the most suitable. |
Please update to v2.2.8. |
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:
Then use the component:
What is expected?
Given the following is valid TS:
There should be no TypeScript errors.
What is actually happening?
The following error is being displayed in VSCode:
Link to minimal reproduction
https://github.com/richmason/vue-ts-issue
Any additional comments?
This was not an issue in version 2.2.4
The text was updated successfully, but these errors were encountered: