Imagine I have a situation where there is an SFC component containing a save
emit:
// ChildComponent.vue
const emit = defineEmits<{
save: [data: { new: Row[]; removed: Row[] }];
}>();
If I needed to access the new
and removed
properties in a parent component, this would be the approach:
// ParentComponent.vue
<ChildComponent
@save="($event) => {
performAPIRemove($event.removed); // TypeScript can correctly infer the type of `$event`
}"
/>
However, let's say I want to define the event callback as a named function. How could I determine the type of the child component's emit?
// ParentComponent.vue
// A possible solution might involve...
function saveCallback(event: typeof ChildComponent.emits.save) {
performAPIRemove(event.removed)
}