+
Skip to content

Typescript for events #437

@jthogsett

Description

@jthogsett

Currently, all of the rhea interfaces that extend EventEmitter do not provide an EventMap generic argument, so event handlers do not have strong typings.

For example,

import { create_container } from 'rhea';

const container = create_container();
container.on('message', function (context) {
  // context is any and has no intellisense or type safety
});

If a generic event map argument is supplied to EventEmitter when extending it, we can get type safety and intellisense on all of the declared events, e.g.

// container.d.ts

type ContainerEvents = {
  'message': [EventContext]
  // add all container events here
};

interface Container extends EventEmitter<ContainerEvents> {
  // ...
}

This will give developers intellisense on event names when registering handlers to the EventEmitters and provide typings on the callback arguments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载