Skip to content

Instantly share code, notes, and snippets.

@baruchvlz
Last active September 24, 2019 17:05
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 baruchvlz/fe91f2f24588fe79392f0cddef6eb1af to your computer and use it in GitHub Desktop.
Save baruchvlz/fe91f2f24588fe79392f0cddef6eb1af to your computer and use it in GitHub Desktop.
fix: better FormModelValue.value type
interface FormModelValue<V = string | number | boolean | undefined | null> {
value: V;
error: boolean;
}
type MapToModel<T> = {
[P in keyof T]: FormModelValue<T[P]>
}
interface Form<M> {
formError: boolean;
underway: boolean;
model: MapToModel<M>;
}
function a<M>(
state: Form<M>
) {
return state;
}
const state = a<{ email: string, password: string }>({
underway: false,
formError: false,
model: {
email: {
value: '',
error: false,
},
password: {
value: '',
error: false,
}
}
})
console.log(state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment