我觉得写稍微抽象一点的代码就很麻烦啊, 大半时间都用来写类型声明了
type Map<T, U, R> = (a: T, b: U) => R;
const map = <T, U, R>(mapTo?: Map<T, U, R>): Map<T, U, R> => (a: T, b: U) => {
return mapTo ? mapTo(a, b) : ({} as R);
};
// dispatch changed?
export const connect = <S1, D, S2 = {}>(
mapStateToProps?: (state: State, ownProps: S2) => S1,
mapDispatchToProps?: (dispatch: React.Dispatch<Action>, props: S2) => D
) => (Component: React.ComponentType<S1 & D & S2>) => (props: S2) => {
这种鬼东西比 c++ templates 可读性还差吧