Skip to content

Instantly share code, notes, and snippets.

@tlaitinen
Created August 1, 2018 10:11
Show Gist options
  • Select an option

  • Save tlaitinen/76a4c2ce237a17a1f13ebfea7474e046 to your computer and use it in GitHub Desktop.

Select an option

Save tlaitinen/76a4c2ce237a17a1f13ebfea7474e046 to your computer and use it in GitHub Desktop.
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