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

Use interface augmnentation #12

Open
zardoy opened this issue Feb 22, 2021 · 0 comments
Open

Use interface augmnentation #12

zardoy opened this issue Feb 22, 2021 · 0 comments

Comments

@zardoy
Copy link

zardoy commented Feb 22, 2021

@orourkek Please have a look at this lib: https://github.com/zardoy/typed-ipc.

I think it's more easy to use since it uses module augmentation.

For instance, we could rewrite your example in this way:

// ipc schema
declare module "typed-ipc" {
 interface IpcMainEvents {
  'no-payload': void;
  'simple-payload': string;
  'complex-payload': {
    foo: string;
    bar: {
      baz: number;
    }
  };
 }
}
// there is no need to export functions

And use it somewhere in main/renderer process:

// everything is type safe and matches the schema, that we declared above
// main
import { typedIpcMain } from "typed-ipc";

typedIpcMain.addEventListener("complex-payload", async (_event, { foo, bar }) => {
	// ...
});

// renderer
import { typedIpcRenderer } from "typed-ipc";

typedIpcRenderer.send("complex-payload", { foo: "str", bar: { baz: 5 } });
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