【发布时间】:2018-08-24 22:32:06
【问题描述】:
在流程中支持$Compose 函数(请参阅recompose as example)。但是,我似乎在打字稿中找不到这样的机制。似乎最好的打字稿可以做的是https://github.com/reactjs/redux/blob/master/index.d.ts#L416-L460。 Typescript 中的$Compose 等价于什么?
编辑:我想要完成的是从recompose 或redux 键入compose 函数,使其类型安全。特别是,对于反应高阶组件,我想确保一个 HOC 的输出 props 满足下一个 HOC 的输入 props。这是我目前的解决方法,并且似乎工作得相当好 - 尽管我希望有一种很好的方法可以在 typescript 中原生地做到这一点。
/** Wraps recompose.compose in a type-safe way */
function composeHOCs<OProps, I1, IProps>(
f1: InferableComponentEnhancerWithProps<I1, OProps>,
f2: InferableComponentEnhancerWithProps<IProps, I1>,
): ComponentEnhancer<IProps, OProps>
function composeHOCs<OProps, I1, I2, IProps>(
f1: InferableComponentEnhancerWithProps<I1, OProps>,
f2: InferableComponentEnhancerWithProps<I2, I1>,
f3: InferableComponentEnhancerWithProps<IProps, I2>,
): ComponentEnhancer<IProps, OProps>
function composeHOCs<OProps, I1, I2, I3, IProps>(
f1: InferableComponentEnhancerWithProps<I1, OProps>,
f2: InferableComponentEnhancerWithProps<I2, I1>,
f3: InferableComponentEnhancerWithProps<I3, I2>,
f4: InferableComponentEnhancerWithProps<IProps, I3>,
): ComponentEnhancer<IProps, OProps>
function composeHOCs(
...fns: Array<InferableComponentEnhancerWithProps<any, any>>
): ComponentEnhancer<any, any> {
return compose(...fns)
}
【问题讨论】:
-
$Compose没有记录,您的链接也不清楚。你能提供一个更详细的解释(也许有例子)它做什么/你想做什么? -
@RyanCavanaugh 澄清了。
标签: typescript types flowtype