Skip to content

Use interface augmnentation #12

@zardoy

Description

@zardoy

@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 } });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions