TS2741 Property '0' is missing in type '{ label: string; } Javascript

人走茶凉 提交于 2019-12-10 19:29:43

问题


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 }

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 is an array, and when I try to run I get this error.

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

Can someone help me?


回答1:


[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 
}


来源:https://stackoverflow.com/questions/54477615/ts2741-property-0-is-missing-in-type-label-string-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!