• Version 3.0.0
  • Published
  • 27 kB
  • No dependencies
  • MIT license


npm i mitt
yarn add mitt
pnpm add mitt


Tiny 200b functional Event Emitter / pubsub.



function mitt

mitt: <Events extends Record<EventType, unknown>>(
all?: EventHandlerMap<Events>
) => Emitter<Events>;
  • Mitt: Tiny (~200b) functional event emitter / pubsub. mitt




interface Emitter

interface Emitter<Events extends Record<EventType, unknown>> {}

    property all

    all: EventHandlerMap<Events>;

      method emit

      emit: {
      <Key extends keyof Events>(type: Key, event: Events[Key]): void;
      <Key extends keyof Events>(
      type: undefined extends Events[Key] ? Key : never
      ): void;

        method off

        off: {
        <Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void;
        (type: '*', handler: WildcardHandler<Events>): void;

          method on

          on: {
          <Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void;
          (type: '*', handler: WildcardHandler<Events>): void;

            Type Aliases

            type EventHandlerList

            type EventHandlerList<T = unknown> = Array<Handler<T>>;

              type EventHandlerMap

              type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<
              keyof Events | '*',
              EventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>

                type EventType

                type EventType = string | symbol;

                  type Handler

                  type Handler<T = unknown> = (event: T) => void;

                    type WildCardEventHandlerList

                    type WildCardEventHandlerList<T = Record<string, unknown>> = Array<

                      type WildcardHandler

                      type WildcardHandler<T = Record<string, unknown>> = (
                      type: keyof T,
                      event: T[keyof T]
                      ) => void;

                        Package Files (1)

                        Dependencies (0)

                        No dependencies.

                        Dev Dependencies (19)

                        Peer Dependencies (0)

                        No peer dependencies.


                        To add a badge like this badgeto your package's README, use the codes available below.

                        You may also use to create a custom badge linking to

                        • Markdown
                        • HTML
                          <a href=""><img src="" alt=""></a>