Keine Überlastung entspricht diesem Aufruf. Überladung 1 von 2,

12

Ich habe store.jsDatei

import { createStore, combineReducers } from "redux";
import reducerADD from "../reducer/reducerADD"

export const store = createStore(combineReducers({ reducerADD}));

Wenn ich das Format in ändere store.tsx , wird ein Fehler angezeigt:

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[]'.

Was ist der Grund dafür?

Jesus
quelle
Was ist die Definition von reducerADD?
Cerberus
const reducerADD = (state = [], action:action) =>{ switch (action.type) { case "ADD": return [...state, ...[action.add]]; default: return state; } }
Jesus

Antworten:

9

Der Staat muss etwas stärker typisiert werden. Es wird versucht, Ihren Ausgangszustand von Typ anyzu Typ umzuwandelnnever .

Wenn Sie den Standardstatus für die Daten erstellen, sollten Sie eine Schnittstelle für Ihren Status definieren. Hier ein Beispiel für ein Aufgabenlistenarray:

interface IAppState {
  toDoList: any[];
}
const initialState: IAppState = {
  toDoList: []
};

export default function reducer(state = initialState, action) {}
Andy
quelle