为什么这不起作用:
function mergeTheme<Props: {}, T: {}>(
Component: React.ComponentType<{ theme: T } & Props>,
injectedTheme: T
): React.ComponentType<{ theme: T } & Props> {
const Themed = (props: { theme: T } & Props) => {
let theme: T = injectedTheme;
return <Component {...props} theme={theme} />;
};
return Themed;
}
错误:
11: return <Component {...props} theme={theme} />;
^ props of React element `Component`. This type is incompatible with
5: function mergeTheme<Props: {}, T: {}>(
^ some incompatible instantiation of `Props`
11: return <Component {...props} theme={theme} />;
^ props of React element `Component`. This type is incompatible with the expected param type of
5: function mergeTheme<Props: {}, T: {}>(
^ some incompatible instantiation of `Props`
但这有效:
function mergeTheme<Props: {}, T: {}>(
Component: React.ComponentType<{ theme: T } & Props>,
injectedTheme: T
): React.ComponentType<{ theme: T } & Props> {
const Themed = (props: { theme: T } & Props) => {
const baseProps: Props = props;
let theme: T = injectedTheme;
return <Component {...props} theme={theme} />;
};
return Themed;
}
两者之间的区别是什么?我如何让第一个工作?