【发布时间】:2018-12-16 16:44:12
【问题描述】:
我目前正在尝试使用 Recompose 在项目中实现 TypeScript 以增强以下组件:
import { compose } from 'recompose';
// This is my Base Component that is reused throughout the App.
interface BaseOuterProps {
value: any;
}
const StatelessBaseComponent = () => <div />;
const BaseComponent = compose<any, BaseOuterProps>(...)(StatelessBaseComponent);
// This is one of the higher components that needs to use the Base Component by enhancing it.
interface HigherInnerProps {
value: any;
something: any;
}
const HigherComponent = compose<HigherInnerProps, any>(...)(BaseComponent);
我遇到的问题是,当 HigherComponent 类型 (HigherInnerProps) 的 props 比 BaseComponent 类型 (BaseOuterProps) 多时,我收到以下错误:
Type 'ComponentClass
' 没有为 签名 '(props: HigherInnerProps & { children?: ReactNode; }, 上下文?:任何):ReactElement |空'
我试图让 BaseOuterProps 更灵活:
interface BaseOuterProps {
value: any;
[key: string]: any | void | null;
}
没有运气。
类型由@types/react 和@types/recompose 提供。
关于如何保留类型链接并满足错误要求的任何想法?
【问题讨论】:
标签: reactjs typescript recompose