我正在为 next.js 页面编写一个 HOC 组件,而这个 HOC 需要接受具有特定getInitialProps
静态功能的组件。
我无法通过流程找出正确的打字方式:
const wrapComponent = (Component: React.ComponentType<*>) => {
const original: Function = Component.getInitialProps;
return class extends React.Component<*> {
static async getInitialProps(ctx) {
const props = await original(ctx);
return {
...props,
custom: 'a',
};
}
render() {
return <Component {...this.props} />;
}
}
}
我收到此错误:
5: const original: Function = Component.getInitialProps;
^ property `getInitialProps`. Property not found in
5: const original: Function = Component.getInitialProps;
^ statics of React$Component