How do I get the type of emit? #9861
-
I'd like to pass component events through a function that does other stuff before it emits the event. This is my working TypeScript code: const emit = defineEmits(['foo', 'bar'])
function emitEvent(eventName: 'foo' | 'bar') {
// do other stuff here
emit(eventName)
} Explicitly naming How would I correctly get the type of the emit events? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You can try using the following method: const emit = defineEmits(['foo', 'bar'])
function emitEvent(eventName:Parameters<typeof emit>[0]) {
// do other stuff here
emit(eventName)
} |
Beta Was this translation helpful? Give feedback.
-
@Alfred-Skyblue What if i want to get the type of emits out of the .vue file? |
Beta Was this translation helpful? Give feedback.
You can try using the following method: