Skip to content

component-lifecycle


component-lifecycle / ExtendableEventMap

Type Alias: ExtendableEventMap<P, TCustom>

ExtendableEventMap<P, TCustom> = NoBaseEventMap<TCustom, P> & Omit<BaseEventMap<P>, keyof TCustom>

Helper type to extend the base event map with custom events. Automatically includes all base events while allowing additional custom events.

Type Parameters

P

P extends string

The prefix used for event names.

TCustom

TCustom extends Record<string, unknown> = Record<string, never>

Custom event map to merge with base events.

Example

typescript
// ✅ Valid - no conflicts
type MyEvents = ExtendableEventMap<"mycomp", {
  "data-loaded": { records: number };
  "validation-failed": { errors: string[] };
}>;

class DataComponent extends Component<"mycomp", MyEvents> {
  async loadData() {
    this.emit("data-loaded", { records: 42 }); // Included by extension
    this.emit("initialized", { component: this }); // Included by default
  }
}

// ❌ Invalid - 'initialized' conflicts
type InvalidEvents = ExtendableEventMap<"mycomp", { initialized: {} }>;
// Results in: { initialized: "❌ Event key \"initialized\" conflicts with base event. Use a different name." }