Search code examples
node.jstypescriptpromisees6-promise

TypeScript Error: Cannot invoke an expression whose type lacks a call signature. Type 'Something' has no compatible call signatures


I have been stuck with this typescript error for the past days.

Cannot invoke an expression whose type lacks a call signature. Type '(<TResult1 = ApiResponse, TResult2 = never>(onfulfilled?: ((value: ApiResponse) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | null | undefined) => Promise<...>) | (<TResult1 = void, TResult2 = never>(onfulfilled?: ((va...' has no compatible call signatures.

Code:

const getDetailsPromise = myCode
              ? storeApi.getDetails(params, [myCode])
              : Promise.resolve();
return getDetailsPromise.then(
              (result: ApiResponse | void) => {
                .......Some logic
                .......Some logic
                return Promise.resolve<
                  [MethodResponse, ResponseHeaders]
                >([ShippingResponse, response.headers]);
              }
            );

storeApi.js

getDetails(
        requestParams: RequestParams,
        myCode: string[]
    ): Promise<ApiResponse> { 
        .......Some logic
        .......Some logic
    }

Here getDetailsPromise returns either Promise or Promise. Also we are expecting myCode type as string if value exists. I am getting the above mentioned error while trying to build the application. Can somebody help/guide me to fix this issue? Any help would be really appreciated.

Playground Link: https://www.typescriptlang.org/play?ts=3.3.3#code/FASwdgLgpgTgZgQwMZQAQEEAOIBKUDOmA9mPmgN7CrWpgIC2UAXKvhDOAObAC+wwSEm1ScoEACJiEIADb5UAXlQAKQQBNmrdlwDaAXQCUTAAowi9EGQA8WXAWKkoAPkUvKNVDDEBXGGFSm5pZQAHRe+EQyAG5Qyu4eNHSMLADkAFIIANZQKQA0VAnU6prFBdQ8BrwA3PyCpBCo9ACeAMJEGoqoKQCMAAy93Sk1BXXCohJSsviBFmSdzW0aZYUJAPwiYpIQ0nLKOgvtUIbLKzQsM8FhBJExygbDow0AFlAyMkSdd66o8dReEL5-OMtjtpmZZqEIC8wMoTqcVOFvDIICxbHhCEI0AAfVBRIggNQGb6-eEef6AgLgy7hG6xRHI+5w058UnURl8YAvN5EO7DYBAA

Thanks in advance!


Solution

  • Thanks to Anatoly. I changed the return type in a wrapper as a Promise with a union type instead of a union of Promise-d types.

    Working Playground Link: https://www.typescriptlang.org/play?ts=4.0.5#code/FASwdgLgpgTgZgQwMZQAQEEAOIBKUDOmA9mPmgN7CrWpgIC2UAXKvhDOAObAC+wwSEm1ScoEACJiEIADb5UAXlQAKQQBNmrdlwDaAXQCUTAAowi9EGQA8WXAWKkoAPkUvKNVDDEBXGGFSm5pZQAHRe+EQyAG5Qyu4eNHSMLADkAFIIANZQKQA0VAnU6prFBdQ8BrwA3PyCpBCo9ACeAMJEGoqoKQCMAAy93Sk1AkINohJSsvgA6jAImJiwncpGAWYW1rZ4hEJoAD6oUUQgai4KbgUgcCrNbRoGqPHUXhC+-uOSENJyyjq37VBDAU+AUXm81kEyGECJEYisaiC6sIPpM5IENmglCivlNZvNFjB4bVRqgABZQGQyIjLB7nR5lTw+PwiMSfb74dHBEIQclgZQMwoeZThbwyCAsLb2XaoA5HE60i6CpWM17MzlQ8Kw2IisUGGrKhJ8A3UPW8fjkylEIn8IA