Żadne przeciążenie nie pasuje do tego połączenia. Przeciążenie 1 z 2,


12

Mam store.jsplik

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

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

Kiedy zmieniam format w store.tsx, pojawia się błąd:

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

Jaki jest tego powód?


Jaka jest definicja reducerADD?
Cerberus,

const reducerADD = (state = [], action:action) =>{ switch (action.type) { case "ADD": return [...state, ...[action.add]]; default: return state; } }
Jezus

Odpowiedzi:


9

Państwo musi być silniej wpisane. Próbuje rzutować stan początkowy z typu anyna typ never.

Podczas tworzenia stanu domyślnego dla danych powinieneś zdefiniować interfejs dla swojego stanu, oto przykład tablicy listy rzeczy do zrobienia:

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

export default function reducer(state = initialState, action) {}
Korzystając z naszej strony potwierdzasz, że przeczytałeś(-aś) i rozumiesz nasze zasady używania plików cookie i zasady ochrony prywatności.
Licensed under cc by-sa 3.0 with attribution required.