Last active
March 27, 2019 19:42
-
-
Save reidev275/fdfcc53fcf705c07643b5015617a8635 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
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 | |
} | |
}; |
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
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