我有
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[]'.
这是什么原因?
状态需要更加强类型化。它试图将您的初始状态从
any
类型转换为 never
类型。
为数据创建默认状态时,您应该为您的状态定义一个接口,以下是待办事项列表数组的示例:
interface IAppState {
toDoList: any[];
}
const initialState: IAppState = {
toDoList: []
};
export default function reducer(state = initialState, action) {}
对于未来的谷歌用户:
如果您忘记使用与函数定义中使用的相同输入来调用函数,这也是返回的错误。
示例:
const handleSaveAll = (currRow: MyItem, fileToUpload: File | undefined) => {
//all the stuff the function does
});
错误:
<Button className={style.btnSave} onClick={handleSaveAll}>
修复:
<Button className={style.btnSave} onClick={() => handleSaveAll(currRow, fileToUpload)}>
就我而言,错误来自格式错误的循环
cards.map(card => {
<EasyGridItem cols={ card.cols }>
<BandcampDailyCard card={ card } />
</EasyGridItem>
})
刚刚将
{}
替换为 ()
我遇到了同样的问题,然后我发现我正在使用
console.table
作为对象,因此我将其更改为 console.log
作为 console.log 对象。它解决了我的问题
const x = moment(
2024-05-12 T13:18:59.000+00:00
).utc().endOf("day").valueOf()
const y = moment().utc().endOf("day").valueOf(