close

[Solved] No overload matches this call. Type ‘string’ is not assignable to type ‘Signals’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error No overload matches this call. Type ‘string’ is not assignable to type ‘Signals’ in nodejs. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How To Solve No overload matches this call. Type ‘string’ is not assignable to type ‘Signals’ Error ?

  1. How To Solve No overload matches this call. Type 'string' is not assignable to type 'Signals' Error?

    To Solve No overload matches this call. Type 'string' is not assignable to type 'Signals' Error This sometimes happens when you have passed an incorrect number of arguments to an anonymous function

  2. No overload matches this call. Type 'string' is not assignable to type 'Signals'

    To Solve No overload matches this call. Type 'string' is not assignable to type 'Signals' Error This sometimes happens when you have passed an incorrect number of arguments to an anonymous function.

Solution 1

This sometimes happens when you have passed an incorrect number of arguments to an anonymous function:

    Object.keys(data).reduce((key: string) => {

    }, {}); 

will raise error:

No overload matches this call. Overload 1 of 3

Pass it the correct number of arguments:

    Object.keys(data).reduce((acc: any, key: string) => {
    }, {});

Solution 2

I also had this strange issue, but I worked around it using type assertions (in my case using a string enum):

(Object.values(someEnum) as string[]).concat(otherStringArray);

Solution 3

Keep numeric enum signals

Object.values(signals)
  // numeric enum includes reverse mapping, filter numbers out and keep "SIGHUP" etc.
  .filter((s): s is NodeJS.Signals => typeof s !== "number") 
  .forEach(signal => {
    process.on(signal, ...) // works now
  })

Solution 4

Use pure signal string literal types

// these string literal items are strongly typed by built-in NodeJS.Signals type
Object.values<NodeJS.Signals>(["SIGHUP", "SIGINT", "SIGTERM"])
  .forEach(signal => {
    process.on(signal, ...) // works now
  })

Solution 5

Change to string enum (no reverse mapping)

enum signals2 {
  SIGHUP = "SIGHUP",
  SIGINT = "SIGINT",
  SIGTERM = "SIGTERM"
}

Object.values(signals2)
  .forEach(signal => {
    process.on(signal, ...) // works now
  })

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment