Last active
September 24, 2019 17:05
-
-
Save baruchvlz/fe91f2f24588fe79392f0cddef6eb1af to your computer and use it in GitHub Desktop.
fix: better FormModelValue.value type
This file contains 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
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