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

feat: strongly typed messages #9

Open
przucidlo opened this issue May 24, 2024 · 0 comments
Open

feat: strongly typed messages #9

przucidlo opened this issue May 24, 2024 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@przucidlo
Copy link
Owner

Describe the solution you'd like

Send methods should be able to accept two types, one internal for electron-broker that enforces consistent message pattern and data, and the second one that just accepts type for message body

type Message<P extends string, D extends Record<any, any> = {}> = [P, D];

interface Foo {
  foo: string;
}

type FooMessage = Message<"pattern", Foo>

brokerClient.send<FooMessage>("pattern", {foo: "bar"});
brokerClient.send<Foo>("untyped-pattern", {foo: "bar"});

It could be possible to enforce strongly typed message handler as well

Why is this needed
Such a change would make refactoring of messages an ease.

@przucidlo przucidlo added the enhancement New feature or request label May 24, 2024
@przucidlo przucidlo added this to the 4.0 milestone Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant