Is there any way to, given a CallExpression with inferred type arguments, find what those type arguments are?
Example code:
class SomeClass {
public someMethod<T>(arg: T): void { }
}
// What is the inferred type of T in this call?
someClass.someMethod(7);
It's easy enough to find type arguments that were explicitly assigned in the code, but I can't figure out how to find what was inferred.
function inferTypeArguments(node: ts.CallExpression, typeChecker: ts.TypeChecker) {
node.typeArguments; // is empty
const signature = typeChecker.getResolvedSignature(node);
signature['typeArguments']; // is also empty
// This returns "<number>(arg: number): void"
// so I know that the typeChecker has the right information,
// but I would really like a ts.Type[]
typeChecker.signatureToString(signature, node, ts.TypeFormatFlags.WriteTypeArgumentsOfSignature)
}