Dev Helpers
← Back

Represent event tuples

Represent event tuples using TypeScript.

Open this example in the interactive library

Source code

type Events = {
  start: { id: number };
  finish: { ms: number };
  failure: { reason: string };
};
console.log(
  (() => {
    type EventArgs = { [K in keyof Events]: [K, Events[K]] }[keyof Events];
    const args: EventArgs = ["start", { id: 3 }];
    return args;
  })(),
);

Sample output

[ 'start', { id: 3 } ]