# StrictEventEmitter

`class` in `services` · v0.8.2

<https://docs.seedcord.org/packages/services/0.8.2/classes/strict-event-emitter>

Typed wrapper around Node.js EventEmitter enforcing tuple payloads per event name.

```ts
class StrictEventEmitter<
    TEvents extends SEEventMapLike<TEvents>
> extends EventEmitter
```

## Methods

### addListener

```ts
public addListener<TEventKey>(
    event: TEventKey,
    listener: (...args: TEvents[TEventKey]) => void
): this
```

Alias of [`on`](/packages/services/0.8.2/classes/strict-event-emitter#on) for compatibility with Node.js EventEmitter APIs.

### emit

```ts
public emit<TEventKey>(
    event: TEventKey,
    args: TEvents[TEventKey]
): boolean
```

Emits an event with the strictly typed argument tuple for the event name.

### eventNamesTyped

```ts
public eventNamesTyped(): SEEventKey<TEvents>[]
```

Returns the list of event names known to the emitter with the mapped key type.

### listenerCountTyped

```ts
public listenerCountTyped<TEventKey>(event: TEventKey): number
```

Counts listeners for an event without widening the return type of listenerCount.

### listeners

```ts
public listeners<TEventKey>(
    event: TEventKey
): ((...args: TEvents[TEventKey]) => void)[]
```

Retrieves the listener list for a given event with the correct tuple signature.

### off

```ts
public off<TEventKey>(
    event: TEventKey,
    listener: (...args: TEvents[TEventKey]) => void
): this
```

Removes a previously registered listener for the given event.

### on

```ts
public on<TEventKey>(
    event: TEventKey,
    listener: (...args: TEvents[TEventKey]) => void
): this
```

Registers a persistent listener with tuple-safe arguments for the given event.

### once

```ts
public once<TEventKey>(
    event: TEventKey,
    listener: (...args: TEvents[TEventKey]) => void
): this
```

Registers a one time listener that is removed after the first invocation.

### removeListener

```ts
public removeListener<TEventKey>(
    event: TEventKey,
    listener: (...args: TEvents[TEventKey]) => void
): this
```

Alias of [`off`](/packages/services/0.8.2/classes/strict-event-emitter#off) for compatibility with Node.js EventEmitter APIs.

### waitFor

```ts
public async waitFor<TEventKey>(
    event: TEventKey,
    opts?: { signal?: AbortSignal; timeoutMs?: number }
): Promise<TEvents[TEventKey]>
```

Waits for an event to be emitted, resolving with the listener arguments tuple once triggered. Supports optional abort signals and timeouts for cancellation semantics.
