私はnext.jsページ用のHOCコンポーネントを作成しています。このHOCは、特定のgetInitialProps
静的関数を持つコンポーネントを受け入れる必要があります。React.ComponentTypeを静的プロパティで入力する方法は?
私は流れと、このための右のタイピングを見つけ出すことができません:私はこのエラーを取得する
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
コンポーネントは 'getInitialProps'方法がありませんでし反応します。それらが特定のコンポーネントである場合、 'React.Component'ではなく' Component'をそのように入力する必要があります。 –
@FelixKlingはクラスインターフェイスを作成することを意味しますか? –
それは私が推測するだろう。 –