Created
August 1, 2018 10:11
-
-
Save tlaitinen/76a4c2ce237a17a1f13ebfea7474e046 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
| import * as t from 'io-ts'; | |
| function request<P extends t.Props>(type:string, props:P) { | |
| return t.type({ | |
| type: t.literal(type), | |
| props: t.type(props) | |
| }); | |
| } | |
| export const RequestT = t.union([ | |
| request('foo', { | |
| baz: t.string, | |
| quux: t.array(t.string) | |
| }), | |
| request('bar', { | |
| a: t.number, | |
| b: t.string | |
| }) | |
| ]); | |
| export type Request = t.TypeOf<typeof RequestT>; | |
| export const ResponseT = t.union([ | |
| t.type({}) | |
| ]) | |
| export type Response = t.TypeOf<typeof ResponseT>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment