Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript for events #437

Open
jthogsett opened this issue Apr 11, 2025 · 0 comments
Open

Typescript for events #437

jthogsett opened this issue Apr 11, 2025 · 0 comments

Comments

@jthogsett
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant