I'm currently debugging some libraries' code and for the life of me don't understand a specific error.
Here is a simplified example of the code I'm debugging:
type Test1Type<V> = object | ((this: V) => object);
function testFnc(x: string, test1Fnc: Test1Type<string>) {
let res;
if (typeof test1Fnc === "function") {
res = test1Fnc.call(x, x);
}
}
In the line res = test1Fnc.call(x, x); the term test1Fnc is marked as an error:
(parameter) test1Fnc: Function | ((this: string) => object)
The 'this' context of type 'Function | ((this: string) => object)' is not assignable to method's 'this' of type '((this: string) => object) & Function'.
Type 'Function' is not assignable to type '((this: string) => object) & Function'.
Type 'Function' is not assignable to type '(this: string) => object'.
Type 'Function' provides no match for the signature '(this: string): object'.ts(2684)
The internal type definition of .call() seems to be this:
call<T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A): R;
Unfortunately, I just cannot figure out what is wrong with this code, especially since the library I'm debugging has this directly in their codebase (see).
I don't really understand what the error message is telling me here.
I'm using "typescript": "~3.9.3" (the library is using "typescript": "^2.8.3").
Any help is appreciated, since I would really like to understand what is going on here.