Repository navigation
Description
π Search Terms
getTypeArgumentsForResolvedSignature, inferred type arguments, resolved signature, signature mapper, native API, missing checker methods, API parity
β 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
Expose the inferred type arguments of a resolved call through the native API client. This is missing in typescript@7.1.0-dev.20261109.1; the API comparison report in #64749 also lists getTypeArgumentsForResolvedSignature as missing.
The JavaScript checker already exposes this operation through #59637 and #60201. The same shape would work on the native client's Checker:
// typescript/sync
getTypeArgumentsForResolvedSignature(signature: Signature): readonly Type[] | undefined;
// typescript/async
getTypeArgumentsForResolvedSignature(signature: Signature): Promise<readonly Type[] | undefined>;The returned types would be client Type objects backed by handles, in the original type-parameter order, with the same semantics as the existing JavaScript-checker method.
π Motivating Example
interface Order {
id: string;
}
declare const order: Order;
declare function parse<T>(value: T): void;
parse(order); // inferred type arguments: [Order]Given the call node, checker.getResolvedSignature(call) resolves the instantiated signature, but signature.getTypeParameters() does not return [Order]. signature.getTarget() gives access to the original signature, without the mapping from T to Order. checker.getTypeArguments() accepts a type reference rather than a signature.
The proposed method would return the type for Order for this call, including when the return type does not mention T.
π» Use Cases
We maintain a compiler plugin that records the type arguments of generic calls, including arguments inferred by the checker. We need the resolved substitution (T = Order), rather than the original type parameter or the value argument's type. The native checker retains that substitution in its signature mapper, but no API operation returns it. Today we rebuild it by matching the instantiated signature against its target, which repeats work the checker has already done and can drift from its inference. Filing it separately since #64709 is triaging missing checker methods before stable.
Activity