unadlib / data-transport

A simple and responsible universal transport

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal: An interface to represent the complete listener and sender types

unadlib opened this issue · comments

In all versions prior to v3.3.6, we defined the interface for interactions like this,

interface Listen {
  hello(options: { num: number }, word: string): Promise<{ text: string }>;
}

interface Emit {
  help(options: { key: number }): Promise<{ text: string }>;
}

const transport: Transport<Listen, Emit> = createTransport(
  'Base',
  ports.create()
);

Such an interface definition above may cause it to be impossible to quickly identify whether the listener interface is the first or the second; when the listener type is missing, the generic type must also be passed any.


It is proposed to modify the interface shape as follows,

interface Interaction {
  listen: {
    hello(options: { num: number }, word: string): Promise<{ text: string }>;
  };
  emit: {
    help(options: { key: number }): Promise<{ text: string }>;
  };
}

const transport: Transport<Interaction> = createTransport(
  'Base',
  ports.create()
);