简体   繁体   中英

Typescript Error Object is of type 'unknown'

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 ,因为itemsitems.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM