Repository navigation
Keep instantiated signature arguments out of parameter lists - #65497
Jake Bailey (jakebailey) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Signature serialization loses display arguments across the public API and type-parameter declarations in still-generic instantiations, while synthesized signature metadata accumulates for the checker’s lifetime.
3 open issues
What changed in this PR
Separates instantiated signature type arguments from type-parameter declarations in the compiler’s synthesized AST, using emit-context metadata to support hover rendering.
Changes:
- Stores signature display arguments separately from AST type-parameter lists.
- Updates the printer to use that metadata and preserves it when cloning or updating nodes.
- Adds checker and API regression tests for declaration structure and signature rendering.
| File | Description |
|---|---|
tsc/internal/printer/printer.go |
Prints signature arguments from emit-context metadata. |
tsc/internal/printer/emitcontext.go |
Stores display arguments and copies them to derived nodes. |
tsc/internal/checker/nodebuilderimpl.go |
Builds display arguments separately from type-parameter declarations. |
tsc/internal/checker/checker_test.go |
Tests AST structure, rendering, cloning, and updates. |
packages/typescript/test/sync/api.test.ts |
Adds synchronous API declaration-structure coverage. |
packages/typescript/test/async/api.test.ts |
Adds asynchronous API declaration-structure coverage. |
Review effort: Balanced
| // } | ||
| // Instantiated arguments are display metadata, not type parameter declarations. | ||
| if len(typeArguments) != 0 { | ||
| b.e.SetSignatureTypeArguments(node, b.f.NewNodeList(typeArguments)) |
There was a problem hiding this comment.
Does this really matter?
90397fa to
407179f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Signature serialization charges hidden constraints and defaults against the display truncation budget, causing short inferred return objects to be incorrectly truncated.
2 open issues
2 resolved since last review
Review effort: Balanced
Signature type parameter lists contain declarations, not the concrete types used to instantiate calls. Preserve real generic parameters and their instantiated constraints even when producing signature displays. Keep instantiation arguments in sparse EmitContext metadata for local hover rendering instead of adding storage to every functionlike node. Scope flagged formatting operations so temporary display trees do not remain on the cached checker context, while ordinary formatting keeps its existing caches. Exclude hidden declaration constraints and defaults from visible length and verbosity accounting without dropping their AST declarations. Return canonical declaration ASTs through the API without transporting hover-only metadata. Preserve native signature and arrow formatting, including clones and updates, and cover instantiated generic methods through native and sync/async API regressions.
407179f to
10637b6
Compare
| b.ctx.approximateLength, b.ctx.truncating = displayLength, displayTruncating | ||
| b.ctx.canIncreaseExpansionDepth, b.ctx.expansionTruncated = canIncreaseExpansionDepth, expansionTruncated |
|
It turns out we need a similar mechanism for another goofy type printing thing; will come up with some combined PR instead. |

Hover sticks type parameter declarations where type parameter arguments should be. We then have to work around this in emit, the type is a lie, etc.
I think it would be wise to stop doing this and instead smuggle this information on the emit resolver instead, thus making the AST types correct so they could be checked in the future.