mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
refactor: strong type for getFormHelpers name (#1029)
This commit is contained in:
@ -17,8 +17,13 @@ interface FormHelpers {
|
|||||||
helperText?: string
|
helperText?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getFormHelpers = <T>(form: FormikContextType<T>, name: string, error?: string): FormHelpers => {
|
export const getFormHelpers = <T>(form: FormikContextType<T>, name: keyof T, error?: string): FormHelpers => {
|
||||||
// getIn is a util function from Formik that gets at any depth of nesting, and is necessary for the types to work
|
if (typeof name !== "string") {
|
||||||
|
throw new Error(`name must be type of string, instead received '${typeof name}'`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getIn is a util function from Formik that gets at any depth of nesting
|
||||||
|
// and is necessary for the types to work
|
||||||
const touched = getIn(form.touched, name)
|
const touched = getIn(form.touched, name)
|
||||||
const errors = error ?? getIn(form.errors, name)
|
const errors = error ?? getIn(form.errors, name)
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user