gpt4 book ai didi

typescript - 参数类型 'saga' 和 'saga' 不兼容

转载 作者:行者123 更新时间:2023-12-04 10:38:22 27 4
gpt4 key购买 nike

我有下一个代码:

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;
}

关于typescript - 参数类型 'saga' 和 'saga' 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60049879/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com