Challenge - 5 Problems
Vue Emits Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the emitted event payload type in this Vue component?
Consider this Vue 3 component using
defineEmits with TypeScript. What is the type of the payload emitted by the update event?Vue
const emit = defineEmits<{ (e: 'update', value: number): void }>() function updateValue() { emit('update', 42) }
Attempts:
2 left
💡 Hint
Look at the second parameter type in the emit definition.
✗ Incorrect
The emit is typed to accept an event named 'update' with a payload of type number. So the emitted payload is a number.
📝 Syntax
intermediate2:00remaining
Which option correctly types multiple emits in Vue 3?
You want to type two emits: 'save' with no payload and 'delete' with a string payload. Which
defineEmits syntax is correct?Attempts:
2 left
💡 Hint
Use function overload syntax for multiple typed emits.
✗ Incorrect
Option D uses function overloads to type each event and its payload correctly. Other options are either untyped or invalid.
🔧 Debug
advanced2:00remaining
Why does this Vue component emit cause a TypeScript error?
This component emits an event 'change' with a string payload, but TypeScript shows an error on emit call. Why?
Vue
const emit = defineEmits<{ (e: 'change', value: number): void }>() emit('change', 'hello')
Attempts:
2 left
💡 Hint
Check the type of the second argument in the emit call.
✗ Incorrect
The emit is defined to accept a number payload for 'change', but the code emits a string, causing a type error.
❓ state_output
advanced2:00remaining
What is the output when emitting an event with typed emits in Vue 3?
Given this component, what will be logged when
trigger is called?Vue
const emit = defineEmits<{ (e: 'log', message: string): void }>() function trigger() { emit('log', 'Hello Vue') console.log('Event emitted') } trigger()
Attempts:
2 left
💡 Hint
Emitting an event does not print anything by itself.
✗ Incorrect
The emit call triggers an event but does not produce console output. Only the console.log prints 'Event emitted'.
🧠 Conceptual
expert2:00remaining
Why use
defineEmits with TypeScript in Vue 3?Which is the main benefit of typing emits with
defineEmits in Vue 3?Attempts:
2 left
💡 Hint
Think about what TypeScript helps prevent.
✗ Incorrect
Typing emits helps catch mistakes like wrong event names or wrong payload types before running the app.