私は、リアクションコンポーネントとオブジェクトを正しいフロータイピングでパラメータとして受け取ろうとしています。したがって、React Componentのパラメータでは、タイプP
の小道があり、P
のプロパティはで、推定タイプはV
である必要があります。私はV
が文字列のオブジェクトであることを認識していますが、別のタイプ(つまり、{ button: string }
は{ checkbox: string }
とは異なります)でもかまいません。 2番目のパラメータは、タイプV
である必要があります。未知の型のフローバウンド多型
機能のポイントは、theme
(これはその反応コンポーネント専用の文字列のオブジェクトです)を必要とする反応コンポーネントを取得し、2番目のパラメータをその小道具として使用して新しい反応コンポーネントを返しますそのtheme
小道具が必要です(すでに与えられているので)。
私はこれでいくつかの試みを行ってきましたが、まだ何か動作していません。
/* @flow */
type FunctionComponent<P> = (props: P) => ?React$Element<any>;
type ClassComponent<D, P, S> = Class<React$Component<D, P, S>>;
type Component<P> = FunctionComponent<P> | ClassComponent<any, P, any>;
type ThemeType = { [className: string]: string };
function mergeTheme<P: { theme: ThemeType }, V: $PropertyType<P, 'theme'>>(
BaseComponent: Component<P>,
injectedTheme: V
): FunctionComponent<$Diff<P, { theme: V }>> {
const ThemedComponent = ownProps => <BaseComponent {...ownProps} theme={injectedTheme} />;
ThemedComponent.displayName = 'Themed(' + BaseComponent.displayName + ')';
return ThemedComponent;
}
フローエラー
12: const ThemedComponent = ownProps => <BaseComponent {...ownProps} theme={injectedTheme} />;
^props of React element `BaseComponent`. Expected object instead of
12: const ThemedComponent = ownProps => <BaseComponent {...ownProps} theme={injectedTheme} />;
^object type
12: const ThemedComponent = ownProps => <BaseComponent {...ownProps} theme={injectedTheme} />;
^props of React element `BaseComponent`. Expected object instead of
12: const ThemedComponent = ownProps => <BaseComponent {...ownProps} theme={injectedTheme} />;
^some incompatible instantiation of `P`
Here's a gist of my various attempts as well
私の本当の目標は、私は、との合併でしょうオプショナルtheme
パラメータを受け入れる新リアクトコンポーネントを持つことが実際にありますinjectedTheme
上記の例ではなく、最初に赤ん坊のステップ。