Redux flowtype如何获取函数返回值列表
我想提取Redux flowtype如何获取函数返回值列表,redux,flowtype,Redux,Flowtype,我想提取mapStateToProps提供给我的道具,作为组件获得的道具列表添加到我自己的道具中。这对我来说似乎很常见,使用react/redux和flow 我可以手动定义我的类型: type StateProps = { activeDuration: ?number, activeColor: ?number, activeAccessories: ?number[], } const mapStateToProps = (state): StateProps =&
mapStateToProps
提供给我的道具,作为组件获得的道具列表添加到我自己的道具中。这对我来说似乎很常见,使用react/redux和flow
我可以手动定义我的类型:
type StateProps = {
activeDuration: ?number,
activeColor: ?number,
activeAccessories: ?number[],
}
const mapStateToProps = (state): StateProps => ({
activeDuration: getActiveDuration(state),
activeColor: getActiveColor(state),
activeAccessories: getActiveAccessories(state),
});
但是所有这些getX
函数都已经知道它们的返回类型。所以实际上mapstatetops
已经知道它的返回类型了。。。
但我不能用:
type Props = { defaultProp: boolean } & mapStateToProps;
因为MapStateTops
是函数本身,而不是返回值
问题是:如何获取(而不是设置)函数将返回的类型。以下代码可以从函数类型中提取返回类型:
type _ExtractReturn<B, F: (...args: any[]) => B> = B;
type ExtractReturn<F> = _ExtractReturn<*, F>;
这个问题不清楚。您是否遇到了意想不到的错误?如果是这样,请提供错误文本和代码片段,以便读者再现错误。不,我没有收到错误。我不知道如何获取我想要的类型。可能是的副本
const mapStateToProps = (state) => ({
activeDuration: getActiveDuration(state),
activeColor: getActiveColor(state),
activeAccessories: getActiveAccessories(state),
});
type StateProps = ExtractReturn<typeof mapStateToProps>
type ExtractReturn<F> =
$PropertyType<$ObjMap<{ x: F }, <R>(f: () => R) => R>, 'x'>