Skip to content

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

@Shujee

Description

@Shujee

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions