Closed
Description
π Search Terms
infer type arguments function call expression
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β Suggestion
interface TypeChecker {
getTypeArgumentsOfSignature(signature: Signature): readonly Type[];
}
π Motivating Example
For the below code, the proposed API is supposed to return [ "text" ]
for the Passthrough("text")
node.
function Passthrough<T>(value: T) {
return value;
}
let str = Passthrough("text");
π» Use Cases
In my own case, I'm writing a TypeScript to C++ compiler and getting the inferred type argument is essential for translating the generic function call to C++.
There are also a few other open source projects getting the information by hacking TypeScript's internals: