feat: strongly typed messages
przucidlo opened this issue · comments
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.