Created
April 23, 2019 06:13
-
-
Save Soul-Master/27a32e472e00b010b2172f977c68d1df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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