小编ady*_*yry的帖子

打字稿,单元测试:正确键入以使用redux-mock-store中的store.dispatch调度Thunk

有什么方法可以从redux-mock-store创建的商店中正确调度Thunk吗?现在我被迫使用任何类型断言

store.dispatch<any>(getCommissions());
Run Code Online (Sandbox Code Playgroud)

dispatch预期的那样提供简单的操作

[ts]
Argument of type '(dispatch: ThunkDispatch<IRootState, undefined, 
AnyAction>, getState: () => IRootState) => void' is not assignable to parameter of type 'AnyAction'.
Property 'type' is missing in type '(dispatch: ThunkDispatch<IRootState, undefined, AnyAction>, getState: () => IRootState) => void'.
Run Code Online (Sandbox Code Playgroud)

的代码片段 getCommisions()

export function getCommissions() {
  return (dispatch: ThunkDispatch<IRootState, undefined, AnyAction>, getState: () => IRootState) => { ... }
Run Code Online (Sandbox Code Playgroud)

unit-testing typescript redux redux-mock-store

5
推荐指数
2
解决办法
1362
查看次数

无法在 Redux + Typescript 连接组件中使用静态 getDerivedStateFromProps

我无法static在连接到 Redux 的类组件中使用方法。打字稿报告

Argument of type 'typeof SAI' is not assignable to parameter of type 'ComponentType<IStateProps & IDispatchProps>'.
  Type 'typeof SAI' is not assignable to type 'StatelessComponent<IStateProps & IDispatchProps>'.
    Type 'typeof SAI' provides no match for the signature '(props: IStateProps & IDispatchProps & { children?: ReactNode; }, context?: any): ReactElement<any> | null'.
Run Code Online (Sandbox Code Playgroud)

容器:

export interface IStateProps {
  saiList: ISaiList
}

const mapStateToProps = (state: IRootState) => ({
  saiList: SaiListSelector(state)
});

export interface IDispatchProps {
  getSai: () => Dispatch<AnyAction>; …
Run Code Online (Sandbox Code Playgroud)

typescript redux react-redux getderivedstatefromprops

2
推荐指数
1
解决办法
3051
查看次数