Ninguna sobrecarga coincide con esta llamada. Sobrecarga 1 de 2,


12

Tengo store.jsarchivo

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

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

Cuando cambio el formato store.tsx, recibo un error:

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

¿Cuál es la razón para esto?


¿Cuál es la definición de reducerADD?
Cerberus

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

Respuestas:


9

El estado necesita ser un poco más fuertemente tipado. Está tratando de convertir su estado inicial de tipo anya tipo never.

Al crear el estado predeterminado para los datos, debe definir una interfaz para su estado, aquí hay un ejemplo para una matriz de lista de tareas pendientes:

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

export default function reducer(state = initialState, action) {}
Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.