类型'Dispatch <rootstate>'不能分配给'Dispatch <anyaction>'

时间:2018-04-24 14:20:01

标签: javascript angular redux redux-observable angular-redux

你好,我试着用angular用户使用redux。 但是当我尝试运行我的角度应用程序时,我有此错误消息:

node_modules/@angular-redux/store/lib/src/components/ng-redux.d.ts(10,31)中的错误:错误TS2420:类'NgRedux'错误地实现了接口'ObservableStore'。   财产'派遣'的类型是不相容的。     类型'Dispatch'不能分配给'Dispatch'类型。       类型'RootState'不能分配给'AnyAction'类型。 node_modules/@angular-redux/store/lib/src/components/ng-redux.d.ts(37,33):错误TS2344:类型'RootState'不满足约束'Action'。 node_modules/@angular-redux/store/lib/src/components/root-store.d.ts(18,24):错误TS2344:类型'RootState'不满足约束'Action'。 node_modules / redux-observable / index.d.ts(32,56):error TS2344:类型'S'不满足约束'Dispatch'。

我的减速机:

export default function reducer(state= {
  persones: [],
  selectedPersone: {},
}, action) {
  let newState;
  switch (action.type) {
    case 'GET_PERSONNES':
      newState = { ...state, persones: action.payload };
      break;
    case 'SELECT_PERSONNE':
      newState = { ...state, selectedPersone: action.payload };
      break;
    case 'POST_PERSONNES':
      newState = { ...state, selectedPersone: action.payload };
      break;
    case 'PUT_PERSONNES':
      newState = { ...state, selectedPersone: {} };
      break;
    default:
      newState = state;
      break;
  }
  return newState;
}

我的减速机指数:

import { combineReducers } from 'redux';

import personnes from './personnes';

export default combineReducers({
  personnes,
} as any);

和我的商店:

import { createStore, applyMiddleware, Store } from 'redux';
import logger from 'redux-logger';
import { createEpicMiddleware } from 'redux-observable';
import { Observable } from 'rxjs';
import reducers from './reducers';
import 'rxjs';


const pingEpic = action$ =>
  action$.ofType('HTTP_GET')
    .debounceTime(500)
    .switchMap(action =>
      Observable.ajax.get(action.payload.url)
        .map((a:any) => {
          console.log(a);
          return { type: action.payload.action, payload: a.response };
        })
      );

const post = action$ =>
  action$.ofType('HTTP_POST')
    .debounceTime(500)
    .switchMap(action =>
      Observable.ajax.post(
        action.payload.url,
        action.payload.object,
      )
        .map((a) => {
          console.log(a);
          return { type: action.payload.action, payload: a.response };
        })
     );  

const put = action$ =>
  action$.ofType('HTTP_PUT')
    .debounceTime(500)
    .switchMap(action =>
      Observable.ajax.put(
        action.payload.url,
        action.payload.object,
      )
        .map((a) => {
          console.log(a);
          return { type: action.payload.action, payload: a.response };
        })
    );


const epicMiddleware = createEpicMiddleware(pingEpic);
const postMidelWare = createEpicMiddleware(post);
const putMidelWare = createEpicMiddleware(put);
export const middleware = applyMiddleware(logger, epicMiddleware, postMidelWare, putMidelWare);

export const store: Store<IAppState> = createStore(reducers, middleware);
你可以帮帮我吗?

谢谢你:)

0 个答案:

没有答案