I updated my typescript packages via npm and now I'm getting the error:
"TS2345: Argument of type '(response: string) => void' is not assignable to parameter of type '((value: {}) => void | PromiseLike) | null | undefined'"
when trying to compile the following code:
private _send<T>(urlPath: string, params?: RequestParams): Promise<T> {
return this._requester.sendRequest<T>(this._datafeedURL, urlPath, params);
}
public getServerTime(callback: ServerTimeCallback): void {
this._send('time')
.then((response: string) => {
const time = parseInt(response);
if (!isNaN(time)) {
callback(time);
}
})
.catch((error?: string | Error) => {
logMessage(`Failed to load server time, error=${getErrorMessage(error)}`);
});
}
The error is coming from the .then line
I've read other similar questions but I can't make sense of the issue for my case.
_send
method body? Or at least what its return type is? – CRiceT
, so it's getting a default type of{}
(which is too broad, causing the issue you're seeing). To see why that inference isn't working, we need to know the signature ofthis._requester.sendRequest
. What is the type ofthis._requester
, and if possible, can you post the code for itssendRequest
method? Or if it's from a library, can you tell us which? – CRicethis._send<string>('time')
. – jcalz