Vue · Middle · Question 19 of 75
How do you type component events with TypeScript?
const emit = defineEmits<{
change: [id: number];
update: [value: string];
}>();- ✓Correct answer: With a type-based
defineEmitsdeclaration listing event names and payload tuples - 2Events can't be typed
- 3With
emit<string>('change')
Explanation
Calling emit('change', 'x') is then a type error, and parents get typed handler arguments. vue-tsc checks templates and SFCs in CI.