Is there a way to declare emits in Vue 3 Options API similar to the Composition API approach? Based on the Composition API documentation: (docs)
<script setup lang="ts">
// type-based
const emit = defineEmits<{
(e: 'change', id: number): void
(e: 'update', value: string): void
}>()
</script>
However, in Options API, we are limited to payload validation only, as explained in the documentation: (docs)
emits: {
addBook(payload: { bookName: string }) {
// perform runtime validation
return payload.bookName.length > 0
}
}
As a result, if validation is not needed, parameters may be flagged as unused by eslint:
emits: {
change: (id: number) => true // 'id' is defined but never used
}