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

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

过去几天我一直被这个 typescript 错误困扰。

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.

代码:

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
    }

这里getDetailsPromise returns要么是Promise,要么是Promise。如果值存在,我们还期望 myCode 类型为字符串。我在尝试构建应用程序时遇到上述错误。有人可以 help/guide 我来解决这个问题吗?任何帮助将不胜感激。

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

提前致谢!

感谢Anatoly。我将包装器中的 return 类型更改为具有联合类型的 Promise,而不是 Promise-d 类型的联合。

工作游乐场Link:https://www.typescriptlang.org/play?ts=4.0.5#code/FASwdgLgpgTgZgQwMZQAQEEAOIBKUDOmA9mPmgN7CrWpgIC2UAXKvhDOAObAC+wwSEm1ScoEACJiEIADb5UAXlQAKQQBNmrdlwDaAXQCUTAAowi9EGQA8WXAWKkoAPkUvKNVDDEBXGGFSm5pZQAHRe+EQyAG5Qyu4eNHSMLADkAFIIANZQKQA0VAnU6prFBdQ8BrwA3PyCpBCo9ACeAMJEGoqoKQCMAAy93Sk1AkINohJSsvgA6jAImJiwncpGAWYW1rZ4hEJoAD6oUUQgai4KbgUgcCrNbRoGqPHUXhC+-uOSENJyyjq37VBDAU+AUXm81kEyGECJEYisaiC6sIPpM5IENmglCivlNZvNFjB4bVRqgABZQGQyIjLB7nR5lTw+PwiMSfb74dHBEIQclgZQMwoeZThbwyCAsLb2XaoA5HE60i6CpWM17MzlQ8Kw2IisUGGrKhJ8A3UPW8fjkylEIn8IA