属性'IntrinsicAttributes&{children ?: ReactNode; }'

I have react project created by Create-React-App having following packages (mentioning packages related to my issue) :

"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1",
"typescript": "^3.9.2",
"@typescript-eslint/eslint-plugin": "^2.33.0",
"@typescript-eslint/parser": "^2.33.0"

我已经创建了一个简单的HOC(到目前为止,它什么都没做,但是稍后会添加我的逻辑),如下所示:

type Props = {
    [key: string]: any;
};


const connect = function (Component: FunctionComponent): FunctionComponent {
    const ComponentWrapper = function (props: Props): ReactElement {
        return <Component {...props} />;
    };

    return ComponentWrapper;
};

并像这样导出我的组件:

    const Test: FunctionComponent<Props> = function ({ message }: Props) {
        return (
            <div>{message}</div>
        );
    };


export default connect(Test);

并像这样使用这个组件:

<Test message="Testing message" />

但是在编译器中出现错误:

Type '{ message: string; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; }'.
  Property 'message' does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }'.  TS2322

我已经尝试过人们在Google上发现的其他类似Stack Overflow问题和文章中所提出的建议,但到目前为止没有任何效果。

评论