Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 979
Giovanni Giampaolo Avatar asked Mar 05 '23 14:03

Giovanni Giampaolo


1 Answers

[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 
}
like image 116
Titian Cernicova-Dragomir Avatar answered Mar 24 '23 13:03

Titian Cernicova-Dragomir