Vue · Middle · Question 19 of 75

How do you type component events with TypeScript?

const emit = defineEmits<{
  change: [id: number];
  update: [value: string];
}>();

Explanation

Calling emit('change', 'x') is then a type error, and parents get typed handler arguments. vue-tsc checks templates and SFCs in CI.

Further reading

Problem with a question

Vue · Middle · question 19

Test yourself

Take the Vue · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz