TS2741类型'{label:string;中缺少属性'0' } Javascript [英] TS2741 Property '0' is missing in type '{ label: string; } Javascript

查看:166
本文介绍了TS2741类型'{label:string;中缺少属性'0' } Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JS和TS编写代码。我已经创建了此界面:

Hi I'm writing a code using JS and TS. I've made this interface:

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

我定义了这个接口来创建一个通用组件。当我尝试在另一个文件中使用此组件时,显然,我必须调用它作为常规组件。但是这里出现了错误。通用组件称为PLTable

I defined this interface for create a general component. When I try to use this component in another file, obliviously I have to call is as a general component. But here it comes the error. The general component it's called PLTable

 <PLTable Conf={CONF}/>

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

CONF is an array, and when I try to run I get this error.


TS2741:类型'{label:string;中缺少属性'0'; } [],但类型 [{key:string; val:任何; }]'。

TS2741: Property '0' is missing in type '{ label: string; }[]' but required in type '[{ key: string; val: any; }]'.

有人可以帮我吗?

推荐答案

[type] 定义一个具有单个元素的元组。您可能希望使用 type [] Array< type>

[type] defines a tuple with a single element. You probably want an array which is defined using type[] or Array<type>

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

这篇关于TS2741类型'{label:string;中缺少属性'0' } Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆