From b007377d3644512e55301bc90cb8cb051ccb3942 Mon Sep 17 00:00:00 2001 From: G r e y Date: Fri, 15 Apr 2022 17:26:57 +0000 Subject: [PATCH] refactor: strong type for getFormHelpers name --- site/src/components/Form/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 { 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