Skip to content

Instantly share code, notes, and snippets.

@reidev275
Last active March 27, 2019 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reidev275/fdfcc53fcf705c07643b5015617a8635 to your computer and use it in GitHub Desktop.
Save reidev275/fdfcc53fcf705c07643b5015617a8635 to your computer and use it in GitHub Desktop.
type Input<A> = { title: string; value: A };
type Form<A> = { [P in keyof A]: Input<A[P]> };
//An example model
type Person = {
firstName: string;
lastName: string;
children: number;
};
//all properties of the Person type must be supplied
//the value must be of the defined type
const form: Form<Person> = {
firstName: {
title: "First Name",
value: "Reid"
},
lastName: {
title: "Last Name",
value: "Evans"
},
children: {
title: "Number of Children",
value: 3
}
};
type FormState<T> = { values: T } & (
| { status: "unsubmitted"; validationFailures: { [K in keyof T]: string } }
| { status: "processing"; message: string }
| { status: "errored"; errors: { [K in keyof T]: string }; message: string }
| { status: "complete"; message: string });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment