问题
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