Description
https://github.com/xiaoxiangmoe/issue-vue-2.7-on-click-type-error.git
pnpm run type-check
src/App.vue:12:6 - error TS2559: Type '{ onClick: any; }' has no properties in common with type 'Readonly<Partial<{}> & Omit<Readonly<ExtractPropTypes<{ border: { type: PropType<boolean>; }; }>>, never>>'.
12 <HelloWorld @click="handleClick" />
~~~~~~~~~~
Found 1 error in src/App.vue:12
HelloWorld.vue
<script setup lang="ts">
interface ButtonProps {
border?: boolean;
}
const props = defineProps<ButtonProps>()
defineEmits<{
(event: 'click',payload: MouseEvent): void
}>()
</script>
<template>
<div id="app">
<button @click="$emit('click', $event)">Click me</button>
</div>
</template>
This error come since vue-tsc 1.7.12
Activity
so1ve commentedon Oct 17, 2023
@xiaoxiangmoe Seemed to be a vue2 type issue. It doesn't convert emits to props
johnsoncodehk commentedon Oct 23, 2023
@LinusBorg could you help transfer this to vuejs/vue? thanks.
so1ve commentedon Nov 15, 2023
? Are you GPT?
anden-akkio commentedon Dec 1, 2023
Also seeing something similar.
Don't think I'm really doing anything special.
Shim file (removing doesn't seem to change anything):
Running type checking with
vue-tsc --noEmit
with this config file:Inheriting from this config file:
ZAID-BAARAB commentedon Jan 20, 2024
It seems like there is a type mismatch between the props defined in HelloWorld.vue and how it is being used in App.vue. You need to make sure that the props passed to the HelloWorld component match the expected props.
so1ve commentedon Jan 21, 2024
In volar we convert
v-on:xxx
toonXxx
and pass them as props to type-check required emits. Vue3 automatically converts events to props but vue2 doesn't. Just FYI @ZAID-BAARAB