Skip to content

Welshman Docs / @welshman/lib / on

Function: on() ​

on<EventMap, E>(target, eventName, callback): () => void

Defined in: packages/lib/src/Tools.ts:1342

A generic type-safe event listener function that works with event emitters.

Type Parameters ​

EventMap ​

EventMap extends Record<string | symbol, any[]>

E ​

E extends string | number | symbol

Parameters ​

target ​

The event target object with add/remove listener methods

off ​

on ​

eventName ​

E

The name of the event to listen for

callback ​

(...args) => void

The callback function to execute when the event occurs

Returns ​

A function that removes the event listener when called

(): void

Returns ​

void