Skip to content

Commit cf8a20d

Browse files
authored
refactor: strong type for getFormHelpers name (#1029)
1 parent 104a3c6 commit cf8a20d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

site/src/components/Form/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ interface FormHelpers {
1717
helperText?: string
1818
}
1919

20-
export const getFormHelpers = <T>(form: FormikContextType<T>, name: string, error?: string): FormHelpers => {
21-
// getIn is a util function from Formik that gets at any depth of nesting, and is necessary for the types to work
20+
export const getFormHelpers = <T>(form: FormikContextType<T>, name: keyof T, error?: string): FormHelpers => {
21+
if (typeof name !== "string") {
22+
throw new Error(`name must be type of string, instead received '${typeof name}'`)
23+
}
24+
25+
// getIn is a util function from Formik that gets at any depth of nesting
26+
// and is necessary for the types to work
2227
const touched = getIn(form.touched, name)
2328
const errors = error ?? getIn(form.errors, name)
2429
return {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy