Skip to content Skip to sidebar Skip to footer

This Expression Is Not Callable Type 'string' Has No Call Signatures

In my Typescript Function, when I set the type annotation to String, I receive the error 'This expression is not callable Type 'String' has no call signatures.' as seen in the code

Solution 1:

You typed setIssuerCallState as a string. And you cannot invoke a string.

You are basically doing:

const aString = "a string"aString() // error

It looks like the proper type for this function would be:

functionIssuerCall(setIssuerCallState: (newState: { message: string }) => void) {
   //...
}

Now setIssuerCallState is typed as a function that takes a single argument that is an object with a message property.

Solution 2:

setIssuerCallState is a function, so setting it as string will give you the error String' has no call signatures.

Try setting the type of setIssuerCallState as setIssuerCallState: (param: any) => void

functionIssuerCall<T>(setIssuerCallState: (param: any) =>void ){

returnAxios.request({
    method: 'get',
    url:'https://jsonplaceholder.typicode.com/todos/',//'https://jsonplaceholder.typicode.com/todos/'
}).subscribe(
    response => {
        console.log(response);
        setIssuerCallState({ message: response.status });
    },
    error => {
        console.log(error);
        setIssuerCallState({ message: '404' });
    }
);
}

Post a Comment for "This Expression Is Not Callable Type 'string' Has No Call Signatures"