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

Open
Shujee opened this issue Apr 15, 2024 · 0 comments

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
None yet
Projects
None yet
Development

No branches or pull requests

1 participant