Break Void and Never
π¨βπΌ Excellent work! You now understand two important return types.
You learned:
- π«
void- Function performs a side effect, returns nothing - β
never- Function never returns (throws or loops forever) - π Exhaustiveness checking - Using
neverto ensure all cases are handled
π¦ Key insight: These types communicate intent.
voidsays "I do something, but don't expect a value back"neversays "I won't returnβever"
This is especially powerful for error handling functions:
function fail(message: string): never {
throw new Error(message)
}
function process(data: string | null): string {
if (data === null) {
fail('Data cannot be null') // TypeScript knows we won't continue
}
return data.toUpperCase() // TypeScript knows data is string here
}
π Congratulations! You've completed the Programming Foundations workshop. You have
the essential skills to write TypeScript code that compiles and communicates its
intent clearly.
Test Your Knowledge
Retrieval practice helps solidify learning by actively recalling information. Use this prompt with your AI assistant to quiz yourself on what you've learned.
Please quiz me on exercise 6 using the epicshop MCP server. Call the get_quiz_instructions tool with exerciseNumber "6" to get the quiz instructions, then quiz me one question at a time.