Skip to content
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

Argument type declaration error on the handler side when using defineEmits + Typescript + setup script #4269

Closed
Shujee opened this issue Apr 15, 2024 · 0 comments · Fixed by vuejs/core#11579
Labels
bug Something isn't working 🍰 p2-nice-to-have

Comments

@Shujee
Copy link

Shujee commented Apr 15, 2024

I'm using Vue 3.3+ syntax for defining my emits:

const emit = defineEmits<{
  ItemClicked: [args: { url: string | undefined, index: number }]
}>()

But when I try to attach a handler function to this emit:

<my-component @ItemClicked="showItem" />

const showItem = (args: { url: string | undefined, index: number }) => {
  //...
}

Typescript keeps show the following error:

Type '(args: { url: string | undefined;    index: number;}) => void' is not assignable to type '($event?: undefined) => any'.
  Types of parameters 'args' and '$event' are incompatible.ts(2322)

My Vue version is 3.4.21 and Typescript is 5.4.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🍰 p2-nice-to-have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants