反应打字稿元素'不可分配给类型

时间:2021-01-16 17:24:34

标签: reactjs typescript

    import * as React from "react";

    import DataTable from "react-data-table-component";
    import Checkbox from "@material-ui/core/Checkbox";


    const isIndeterminate = indeterminate => indeterminate;
    const selectableRowsComponentProps = { indeterminate: isIndeterminate };


    class BarChart extends React.Component<any, any> {
        constructor(props){
            super(props);
            this.state = {

            }
        }


    render() {
        const {
        columns,
        rec_columns,
        data
        } = this.state;
        
        return (
            <div className="cluster-menu style-2">
            <DataTable
            columns={columns}
            data={data}
            defaultSortField="title"
            // sortIcon={<SortIcon />}
            pagination
            selectableRows
            selectableRowsComponent={Checkbox}
            selectableRowsComponentProps={{selectableRowsComponentProps}}
            />
        </div>
        );
    }
    }

    export default BarChart;

这是我的反应代码。我正在使用打字稿

我收到以下错误。 错误是因为 selectableRowsComponent={Checkbox} 行 在我的 vs 代码中,checkbox 显示红线

    ERROR in src/app/react-wrapper/BarChart.tsx(885,58): error TS2322: Type '(props: CheckboxProps) => Element' is not assignable to type '"input" | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>'.
    Type '(props: CheckboxProps) => Element' is missing the following properties from type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>': type, props, key
    src/app/react-wrapper/BarChart.tsx(898,49): error TS2322: Type '(props: CheckboxProps) => Element' is not assignable to type '"input" | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>'.
    Type '(props: CheckboxProps) => Element' is not assignable to type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>'.
    src/app/react-wrapper/BarChart.tsx(910,49): error TS2322: Type '(props: CheckboxProps) => Element' is not assignable to type '"input" | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>'.
    Type '(props: CheckboxProps) => Element' is not assignable to type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>'.
    src/app/react-wrapper/BarChart.tsx(958,49): error TS2322: Type '(props: CheckboxProps) => Element' is not assignable to type '"input" | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>'.
    Type '(props: CheckboxProps) => Element' is not assignable to type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>'.

我遇到了上述错误。 错误是因为 selectableRowsComponent={Checkbox} 行 在我的 vs 代码中,checkbox 显示红线

请看看会出现什么问题。

0 个答案:

没有答案