Typing Event Maps
Map event names to their payload types.
What Is an Event Map?
An event map is an interface that links each event name to the shape of its payload. It is the single source of truth for an event system.
interface Events {
login: { userId: string };
logout: void;
}
// "login" carries a payload; "logout" carries none.Mapping Names to Payloads
Each property key is an event name and its value type is the payload. This lets the type system know exactly what data each event expects.
interface Events {
message: { text: string; from: string };
typing: { userId: string };
}
const sample: Events["message"] = { text: "hi", from: "ada" };
console.log(sample.text, sample.from);