-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Open
Labels
Description
Vue version
3.5
Link to minimal reproduction
Steps to reproduce
create a custom component with a generic T, defineModel and defineEmits like the code below
<script setup lang="ts" generic="T extends Item, U extends T">
export type Item = {
text: string;
value: string
}
const props = defineProps<{ items: T[] }>()
const model = defineModel<U[]>()
defineEmits<{
'update:modelValue': [items: U[]]
}>()
</script>
<template>
<div>
<slot />
</div>
</template>
and from you parent component use this
<script setup>
import { ref } from 'vue'
import Comp from './Comp.vue';
const myModel = ref([{
text: 'text', value: 'value'
}])
</script>
<template>
<Comp v-model="myModel" :items="[{ text: 'some item', value: 'some item' }]" @update:modelValue=""></Comp>
</template>
and if I hover the @update:modelValue
I get unknown args instead of T
What is expected?
I should see the type of T when hover on @update:modelValue
What is actually happening?
I found out this this happens only on vue 3.5, when using 3.4 it works well
3.5
3.4
I also noticed that this happens only for @update:modelValue
, for example if I have @update:modelAnythingElse
in vue 3.5 it works just fine
and I also noticed that only if I call the defineEmits()
in the child component this happens
if I don't call the defineEmits()
the types are correct on the default @update:modelValue
System Info
System:
OS: macOS 14.6.1
CPU: (14) arm64 Apple M3 Max
Memory: 167.28 MB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
pnpm: 9.0.6 - /opt/homebrew/bin/pnpm
Watchman: 2024.10.14.00 - /opt/homebrew/bin/watchman
Browsers:
Brave Browser: 127.1.68.128
Chrome: 130.0.6723.58
Safari: 17.6
Any additional comments?
No response
DrWarpMan and jacksongrossLeanderD
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
jacksongross commentedon Dec 5, 2024
I am seeing the same, even without generics. The workaround I found so far is to define the emits with the regular type-based syntax as per the docs, so in your case would be:
It would be good if we could have the types inferred correctly with the succinct syntax.
KazariEX commentedon Dec 9, 2024
It is not necessary to use both
defineEmits
to specify the update event formodelValue
, as it is automatically generated.