Skip to content

Commit

Permalink
PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
norda-gunni committed Dec 13, 2024
1 parent 11c905b commit 7d95f67
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ export const NationalIdWithName: FC<
const [personName, setPersonName] = useState('')
const [companyName, setCompanyName] = useState('')

const getFieldErrorString = (error: any, id: string): string | undefined => {
/**
* Errors that occur in a field-array have incorrect typing
* This hack is needed to get the correct type
*/
const errorList = error as unknown as Record<string, string>[] | undefined
return (errorList?.[id as any] as unknown as string) ?? undefined
const getFieldErrorString = (
error: unknown,
id: string,
): string | undefined => {
if (!error || typeof error !== 'object') return undefined

const errorList = error as Record<string, unknown>[]
if (!Array.isArray(errorList)) return undefined

const fieldError = errorList[id as any]
return typeof fieldError === 'string' ? fieldError : undefined
}

// get national id validation errors
Expand Down

0 comments on commit 7d95f67

Please sign in to comment.