Search code examples
typescriptvuejs3

How can I define an emit which doesn't have any args in Vue 3.3+ ? (TypeScript)


From Vue 3.3 is possible to define emits in TypeScript like this

<script setup lang="ts">
const emit = defineEmits<{
  change: [id: number]
  update: [value: string]
}>()
</script>

How can I define an emit which doesn't require any args?


Solution

  • To define a emit that doesn't require any args in Vue 3.3+ with Typescript, you can simply omit the argument type:

     <script setup lang="ts">
       const emit = defineEmits<{
         change: []
         update: []
       }>()
     </script>