参数类型 'saga' 和 'saga' 不兼容
Types of parameters 'saga' and 'saga' are incompatible
我有下一个代码:
const sagaMiddleware = createSagaMiddleware(options);
.
.
.
const createdStore = createStore(
create(),
state,
someMiddleware,
) as someStore;
createdStore.runSaga = sagaMiddleware.run; // error here
在升级到最新的 redux-saga 1.1.3 版本之前工作正常。现在我收到下一个错误:
Type '<S extends Saga<any[]>>(saga: S, ...args: Parameters<S>) => Task' is not assignable to type '(saga: (() => IterableIterator<any>) | undefined, args: any) => any'.
Types of parameters 'saga' and 'saga' are incompatible.
Type '(() => IterableIterator<any>) | undefined' is not assignable to type 'Saga<any[]>'.
Type 'undefined' is not assignable to type 'Saga<any[]>'.
如何解决?
我在使用 redux-boilerplate-typescript
时遇到了同样的问题。我最终在 types/index.d.ts:
中执行了以下操作
import { Saga } from '@redux-saga/types';
然后我变了
export interface InjectedStore extends Store {
injectedReducers: any;
injectedSagas: any;
runSaga(
saga: (() => IterableIterator<any>) | undefined,
args: any | undefined,
): any;
}
到
export interface InjectedStore extends Store {
injectedReducers: any;
injectedSagas: any;
runSaga(
saga: Saga | (() => IterableIterator<any>) | undefined,
args: any | undefined,
): any;
}
我有下一个代码:
const sagaMiddleware = createSagaMiddleware(options);
.
.
.
const createdStore = createStore(
create(),
state,
someMiddleware,
) as someStore;
createdStore.runSaga = sagaMiddleware.run; // error here
在升级到最新的 redux-saga 1.1.3 版本之前工作正常。现在我收到下一个错误:
Type '<S extends Saga<any[]>>(saga: S, ...args: Parameters<S>) => Task' is not assignable to type '(saga: (() => IterableIterator<any>) | undefined, args: any) => any'.
Types of parameters 'saga' and 'saga' are incompatible.
Type '(() => IterableIterator<any>) | undefined' is not assignable to type 'Saga<any[]>'.
Type 'undefined' is not assignable to type 'Saga<any[]>'.
如何解决?
我在使用 redux-boilerplate-typescript
时遇到了同样的问题。我最终在 types/index.d.ts:
import { Saga } from '@redux-saga/types';
然后我变了
export interface InjectedStore extends Store {
injectedReducers: any;
injectedSagas: any;
runSaga(
saga: (() => IterableIterator<any>) | undefined,
args: any | undefined,
): any;
}
到
export interface InjectedStore extends Store {
injectedReducers: any;
injectedSagas: any;
runSaga(
saga: Saga | (() => IterableIterator<any>) | undefined,
args: any | undefined,
): any;
}