我想用如下的打字稿定义一个React15包装器组件:
export default (
bodyRef: (r: HTMLElement | null) => void,
WrappedComponent: new () => React.Component
) => <WrappedComponent ref={(r) => bodyRef(r)} />;
但是它抱怨ref=...
中的<WrappedComponent
:
Argument of type 'Component<{}, {}> | null' is not assignable to parameter of type 'HTMLElement | null'.
Type 'Component<{}, {}>' is not assignable to type 'HTMLElement'.
Property 'accessKey' is missing in type 'Component<{}, {}>'.
如何为ref
参数定义正确的类型?