New to Typescript and can't figure this error I am getting. I am using final form and pushing items into an array. I can console.log the values and see the array and the items in the array. But when I pass this to my child component I keep getting the error:
Object is of type 'unknown
Parent Component
<Form
onSubmit={onFormSubmit}
initialValues={{ items: [{ item: '' }, { item: '' }]}}
mutators={{ ...arrayMutators }}
>
<List values={values} />
//no TS error
Child Component
//List.tsx
<Button disabled={values.items.length === 10}>Add item</Button>
//TS error for values.items (Object is of type 'unknown')
Type Declaration:
values: Record<string, unknown>;
if values
types are unknown
, you can't use items.length
at the List
component, because items
is undefined
under the hood.