Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No overload matches this call. Overload 1 of 2,

I have store.js file

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

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

When I change format in store.tsx I'm getting an 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[]'.

What is the reason for this?

like image 302
Silicum Silium Avatar asked Oct 04 '19 09:10

Silicum Silium


People also ask

What does no overload matches this call mean?

The error "No overload matches this call" occurs when we call a function and pass it a parameter that doesn't match any of its specified overloads. To solve the error, make sure the function is being called with the correct number of arguments of the correct type, or use a type assertion.

How do you ignore no overload matches this call?

To fix the "No overload matches this call. Type 'string' is not assignable to type 'Signals'" error in TypeScript, we can use a type guard to filter out the values that don't have the Signals type. enum Signals { SIGHUP = 1, SIGINT = 2, SIGTERM = 15, } Object.


2 Answers

The state needs to be abit more strongly typed. Its trying to cast your initial state from type any to type never.

When creating the default state for the data you should define an interface for your state, here's an example for a todo list array:

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

export default function reducer(state = initialState, action) {}
like image 148
Andy Avatar answered Sep 19 '22 13:09

Andy


For future googlers:

This is also the error returned if you forget to call your function with the same inputs as used in the function definition.

Example:

const handleSaveAll = (currRow: MyItem, fileToUpload: File | undefined) => {
    //all the stuff the function does
});

The Error:

<Button className={style.btnSave} onClick={handleSaveAll}>

The Fix:

<Button className={style.btnSave} onClick={() => handleSaveAll(currRow, fileToUpload)}>
like image 20
cssyphus Avatar answered Sep 19 '22 13:09

cssyphus