“This expression is not callable. Type ‘String’ has no call signatures” – How To Fix It?

This expression is not callable. Type 'String' has no call signatures

This expression is not callable. Type ‘String’ has no call signatures” is a common error in TypeScript. If you are struggling and don’t know how to fix it, then don’t worry because in our instructions, we will demonstrate the cause and some common methods to solve this issue.

What causes this problem?

First of all, let’s take a look at example 1:

var myStr = "Welcome to LearnShareIT.com!";

console.log(myStr());

Output: 

This expression is not callable.
  Type 'String' has no call signatures.

If we look carefully, we will notice that we declare myStr as a string but try to call it as a function

This seems to be a “impossible-to-make” mistake, but in fact, when working on a large project, this is a very common error. Check out example 2: 

// Creating a function to print out the name, age, and website of a person
function Person(name:string, age:number, website:string) {
    console.log("Name: ", name);
    console.log("Age: ", age);
    console.log("Website: ", website);
}

var person = "nhk";
var personAge = 18;
var personWebsite = "LearnShareIT.com";

person(person, personAge, personWebsite);

Output

This expression is not callable.
  Type 'String' has no call signatures.

If we take a closer look, we can see that our function is Person, but we are trying to call person, which is declared as a string. TypeScript is case sensitive, so it differentiates between uppercase and lowercase characters. Therefore, in this example, we are trying to call a string as a function, and thus TypeScript throws this error. 

How to fix the error “This expression is not callable. Type ‘String’ has no call signatures” in TypeScript?

Most of the time, this error occurs because of our carelessness. So here are some possible solutions to solve this problem: 

Be careful with names

In example 2, we have shown you how a small little character can lead to an unnecessary error in the program. It is just a p and P that makes the difference. The correct code has to be: 

// Creating a function to print out the name, age, and website of a person
function Person(name:string, age:number, website:string) {
    console.log("Name: ", name);
    console.log("Age: ", age);
    console.log("Website: ", website);
}

var person = "nhk";
var personAge = 18;
var personWebsite = "LearnShareIT.com";

Person(person, personAge, personWebsite);

Output: 

Name: nhk
Age: 18
Website: LearnShareIT.com

So, be aware of the names of the variables, especially with the uppercase and lowercase since TypeScript is case-sensitive.

Check if you are trying to use a string built-in method 

Sometimes, you are trying to use a built-in method on the string but forget to add it into the code. For example, this can possibly happen in example 1: 

var myStr = "Welcome to LearnShareIT.com!";

// Chage all the characters of the string into uppercase letters
console.log(myStr.toUpperCase());

Output:

WELCOME TO LEARNSHAREIT.COM!

As you can see, we are trying to use the toUpperCase method on our string, but forget to add it in our code. So, check the syntax carefully.

Summary

In this tutorial, we have shown you how to fix the error “This expression is not callable. Type ‘String’ has no call signatures” in TypeScript. This problem occurs when we are trying to call a string as a function. The way to fix it is very simple: check the code carefully so that we don’t use any string as a function by accident. Let’s try it!

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *