diff --git a/site/src/components/Form/index.ts b/site/src/components/Form/index.ts index 3eae433c00162..80f466b783918 100644 --- a/site/src/components/Form/index.ts +++ b/site/src/components/Form/index.ts @@ -17,8 +17,13 @@ interface FormHelpers { helperText?: string } -export const getFormHelpers = (form: FormikContextType, name: string, 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 +export const getFormHelpers = (form: FormikContextType, name: keyof T, error?: string): FormHelpers => { + 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 errors = error ?? getIn(form.errors, name) return {