Is there a way to properly access the type of an explicit 'this' parameter from a ts.Signature using the compiler API?
// Code being compiled
interface Fn1 {
(this: Foo): void;
}
const fn1: Fn1 = () => {};
interface Fn2<T> {
(this: T): void;
}
const fn2: Fn2<void> = () => {};
// Compiler API
function visitVariableDeclaration(node: ts.VariableDeclaration, checker: ts.TypeChecker) {
const type = checker.getTypeAtLocation(node.type);
const signatures = checker.getSignaturesOfType(type, ts.SignatureKind.Call);
const signature = signatures[0];
// How do I access type of 'this' on signature?
}
Currently, I can call getDeclaration() and look at the parameters, which works for Fn1. However, for Fn2, it won't resolve 'T' to 'void'. When tracing through with the debugger, I can see that signature has a member called 'thisParameter' which seems like it has what I need. But since this is not publicly exposed through the interface, I can't depend on it. Are there any other ways to properly access the type?