我有store.js
文件
import { createStore, combineReducers } from "redux";
import reducerADD from "../reducer/reducerADD"
export const store = createStore(combineReducers({ reducerADD}));
当我在store.tsx
中更改格式时,我收到一个错误:
No overload matches this call.
Overload 1 of 2, '(reducers: ReducersMapObject<{ reducerADD: { lastName: string; firstName: string; password: string; email: string; }[]; }, any>): Reducer<{ reducerADD: { lastName: string; firstName: string; password: string; email: string; }[]; }, AnyAction>', gave the following error.
Type '(state: never[] | undefined, action: action) => { lastName: string; firstName: string; password: string; email: string; }[]' is not assignable to type 'Reducer<{ lastName: string; firstName: string; password: string; email: string; }[], any>'.
Types of parameters 'state' and 'state' are incompatible.
Type '{ lastName: string; firstName: string; password: string; email: string; }[] | undefined' is not assignable to type 'never[] | undefined'.
Type '{ lastName: string; firstName: string; password: string; email: string; }[]' is not assignable to type 'never[]'.
Type '{ lastName: string; firstName: string; password: string; email: string; }' is not assignable to type 'never'.
Overload 2 of 2, '(reducers: ReducersMapObject<{ reducerADD: { lastName: string; firstName: string; password: string; email: string; }[]; }, AnyAction>): Reducer<{ reducerADD: { lastName: string; firstName: string; password: string; email: string; }[]; }, AnyAction>', gave the following error.
Type '(state: never[] | undefined, action: action) => { lastName: string; firstName: string; password: string; email: string; }[]' is not assignable to type 'Reducer<{ lastName: string; firstName: string; password: string; email: string; }[], AnyAction>'.
Types of parameters 'state' and 'state' are incompatible.
Type '{ lastName: string; firstName: string; password: string; email: string; }[] | undefined' is not assignable to type 'never[] | undefined'.
Type '{ lastName: string; firstName: string; password: string; email: string; }[]' is not assignable to type 'never[]'.
原因何在?
4条答案
按热度按时间mznpcxlj1#
状态需要稍微强一些。它试图将初始状态从类型
any
强制转换为类型never
。在创建数据的默认状态时,应该为状态定义一个接口,下面是一个todo列表数组的示例:
fhg3lkii2#
对于未来的谷歌人:
如果您忘记使用函数定义中使用的相同输入调用函数,也会返回此错误。
示例:
错误:
修复:
wfauudbj3#
我遇到了同样的问题,然后我发现我使用的是
console.table
对象,因此我将其改为console.log
console.log对象.它解决了我的问题hkmswyz64#
在我的例子中,错误来自于一个格式错误的循环
刚刚将
{}
更换为()