您好,我正在使用 JS 和 TS 编写代码。我做了这个界面:
> interface IPLTableProps {
> Conf: [{ key: string, val: any }],
> Values?: [string],
> children?: ReactNode // TODO prendere children da React }
我定义这个接口(interface)是为了创建一个通用组件。当我尝试在另一个文件中使用此组件时,我不经意地必须将 is 作为通用组件调用。但是这里出现了错误。通用组件它叫做 PLTable
<PLTable Conf={CONF}/>
CONF 是一个数组,当我尝试运行时出现此错误。
TS2741: Property '0' is missing in type '{ label: string; }[]' but required in type '[{ key: string; val: any; }]'.
有人可以帮助我吗?
最佳答案
[type]
定义具有单个元素的元组。您可能需要一个使用 type[]
定义的数组或 Array<type>
interface IPLTableProps {
Conf: Array<{ key: string, val: any }>,
Values?: string[],
children?: ReactNode
}
关于javascript - TS2741 类型 '{ 标签 : string; } Javascript 中缺少属性 '0',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54477615/