Skip to content

Instantly share code, notes, and snippets.

@Soul-Master
Created April 23, 2019 06:13
Show Gist options
  • Save Soul-Master/27a32e472e00b010b2172f977c68d1df to your computer and use it in GitHub Desktop.
Save Soul-Master/27a32e472e00b010b2172f977c68d1df to your computer and use it in GitHub Desktop.
interface MessageMap {
method1: { prop1: string };
method2: { prop2: string };
method3: { prop3: string };
}
export type RequestMessage<T> = {
[P in keyof T]: { action: P, data: T[P] }
}[keyof T];
const x: RequestMessage<MessageMap> = null;
switch (x.action) {
case 'method1':
var p1 = x.data.prop1;
break;
case 'method2':
var p1 = x.data.prop2;
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment