Last active
January 1, 2019 05:03
-
-
Save siassaj/5d627b44eb8b48728d1b0f705df3c1b5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Action<K extends keyof typeof ops> { | |
| action: K; | |
| data: (typeof ops[K]) extends (arg: infer T) => any ? T : undefined | |
| } | |
| const ops = { | |
| setFire: (data: { place: string }) => data, | |
| extinguish: (data: { extinguisherType: string }) => data | |
| } | |
| // this works fine, but is a little verbose | |
| const action: Action<"setFire"> = { | |
| action: "setFire", | |
| data: { place: "over there" } | |
| } | |
| // this doesn't work, is there a way to make it work by changing the type signature of Action ? | |
| const action: Action = { | |
| action: "setFire", | |
| data: { place: "over there" } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment