Skip to content

eventClasses

Prefer EventTarget over EventEmitter for cross-platform compatibility.

✅ This rule is included in the node logical and logicalStrict presets.

While EventEmitter is only available in Node.js, EventTarget is available in browsers, Deno, and modern Node.js (v14.5+). Using EventTarget makes code more cross-platform friendly and can reduce bundle size in built packages.

import {
class EventEmitter<T extends EventMap<T> = DefaultEventMap>
interface EventEmitter<T extends EventMap<T> = DefaultEventMap>

The EventEmitter class is defined and exposed by the node:events module:

import { EventEmitter } from 'node:events';

All EventEmitters emit the event 'newListener' when new listeners are added and 'removeListener' when existing listeners are removed.

It supports the following option:

@sincev0.1.26

EventEmitter
} from "events";
class
class MyEmitter
MyEmitter
extends
class EventEmitter<T extends EventMap<T> = DefaultEventMap>

The EventEmitter class is defined and exposed by the node:events module:

import { EventEmitter } from 'node:events';

All EventEmitters emit the event 'newListener' when new listeners are added and 'removeListener' when existing listeners are removed.

It supports the following option:

@sincev0.1.26

EventEmitter
{}
const
const emitter: EventEmitter<DefaultEventMap>
emitter
= new
new EventEmitter<DefaultEventMap>(options?: EventEmitterOptions): EventEmitter<DefaultEventMap>

The EventEmitter class is defined and exposed by the node:events module:

import { EventEmitter } from 'node:events';

All EventEmitters emit the event 'newListener' when new listeners are added and 'removeListener' when existing listeners are removed.

It supports the following option:

@sincev0.1.26

EventEmitter
();

This rule is not configurable.

If your code exclusively targets Node.js environments and you specifically need EventEmitter’s API features that are not available in EventTarget (for example, prependListener, once returning a cleanup function, or error events with special handling), you might choose not to enable this rule.

Made with ❤️‍🔥 around the world by the Flint team and contributors.