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>;
如果values
类型是unknown
,则不能在List
组件中使用items.length
,因为items
在items.length
undefined
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.