【问题标题】:TS2741 Property '0' is missing in type '{ label: string; } JavascriptTS2741 类型 '{ 标签:字符串中缺少属性 '0'; } Javascript
【发布时间】:2019-06-25 22:04:04
【问题描述】:

您好,我正在使用 JS 和 TS 编写代码。我做了这个界面:

> interface IPLTableProps {
>     Conf: [{ key: string, val: any }],
>     Values?: [string],
>     children?: ReactNode // TODO prendere children da React }

我定义了这个接口来创建一个通用组件。当我尝试在另一个文件中使用这个组件时,不知不觉我不得不将其称为通用组件。但是这里出现了错误。通用组件叫PLTable

 <PLTable Conf={CONF}/>

CONF 是一个数组,当我尝试运行时出现此错误。

TS2741:类型 '{ label: string; 中缺少属性 '0'; }[]' 但 类型 '[{ 键:字符串;值:任何; }]'。

有人可以帮我吗?

【问题讨论】:

    标签: javascript html typescript components


    【解决方案1】:

    [type] 定义了一个具有单个元素的元组。您可能需要使用type[]Array&lt;type&gt; 定义的数组

    interface IPLTableProps {
        Conf: Array<{ key: string, val: any }>,
        Values?: string[],
        children?: ReactNode 
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-30
      • 2022-11-16
      • 2020-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 2019-11-19
      • 2017-11-10
      相关资源
      最近更新 更多