Callback function types
📖 Scenario: You are building a simple event handler system where functions are called back when an event happens.
🎯 Goal: Create a callback function type, use it to type a function parameter, and call the callback with a message.
📋 What You'll Learn
Create a callback type named
Callback that accepts a single string parameter and returns void.Create a function named
triggerEvent that takes a message of type string and a callback of type Callback.Inside
triggerEvent, call the callback with the message.Call
triggerEvent with the message 'Hello, TypeScript!' and a callback that prints the message.💡 Why This Matters
🌍 Real World
Callbacks are used in many programs to run code after something happens, like a button click or data loading.
💼 Career
Understanding callback types helps you write safer and clearer TypeScript code, which is important for frontend and backend development.
Progress0 / 4 steps