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 我来解决这个问题吗?任何帮助将不胜感激。
提前致谢!
感谢Anatoly。我将包装器中的 return 类型更改为具有联合类型的 Promise,而不是 Promise-d 类型的联合。
过去几天我一直被这个 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 我来解决这个问题吗?任何帮助将不胜感激。
提前致谢!
感谢Anatoly。我将包装器中的 return 类型更改为具有联合类型的 Promise,而不是 Promise-d 类型的联合。