Skip to content

Add instantiated symbol mapper into context mapper when reprinting nodes we instantiate before printing - #64680

Open
Wesley Wigham (weswigham) wants to merge 1 commit into
microsoft:mainfrom
weswigham:declaration-emit-type-param-leak-fix
Open

Wesley Wigham (weswigham) wants to merge 1 commit into
microsoft:mainfrom
weswigham:declaration-emit-type-param-leak-fix

Conversation

@weswigham

Copy link
Copy Markdown
Member

Fixes #64614

The instantiated symbol mapper from the inferred query call wasn't being included in the type we were serializing, so we producing uninstantiated type parameters. By merging it into the node builder context mapper, it correctly propagates down into the nodes we try and serialize for the return type for that signature (...and in turn evaluates it, producing a follow-on any from the missing import, but the project has noImplicitAny: false so what are you gonna do)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Mapper self-composition can over-instantiate types, and the regression test does not reproduce the linked issue’s required signature shape.

2 open findings
What changed in this PR

Fixes declaration emit leaking uninstantiated type parameters by propagating symbol mappers during type-node serialization.

Changes:

  • Composes instantiated-symbol mappers into node-builder context.
  • Adds compiler and transpile regression coverage.
  • Updates affected type and declaration baselines.
File Description
tsc/​internal/​checker/​nodebuilderimpl.go Propagates instantiated-symbol mappers.
tsc/​internal/​checker/​pseudotypenodebuilder.go Falls back when direct nodes require mapping.
tsc/​testdata/​tests/​cases/​compiler/​declarationEmitUninstantiatedConditionalTypeParameters.ts Adds declaration-emit regression test.
tsc/​testdata/​tests/​cases/​transpile/​declarationEmitUnresolvedGenericAnnotations.ts Tests unresolved generic annotations.
tsc/​testdata/​baselines/​reference/​transpile/​declarationEmitUnresolvedGenericAnnotations.d.ts Records transpile declaration output.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitUninstantiatedConditionalTypeParameters.js Records declaration emit.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitUninstantiatedConditionalTypeParameters.symbols Records symbol output.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitUninstantiatedConditionalTypeParameters.types Records inferred types.
tsc/​testdata/​baselines/​reference/​compiler/​declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types Updates recursive-type output.
tsc/​testdata/​baselines/​reference/​compiler/​es2018ObjectAssign.types Updates union ordering.
tsc/​testdata/​baselines/​reference/​conformance/​usePromiseFinally(target=es2015).types Updates Promise type ordering.
tsc/​testdata/​baselines/​reference/​conformance/​parserRealSource8.types Updates instantiated method display.
tsc/​testdata/​baselines/​reference/​conformance/​parserRealSource14.types Updates instantiated array method display.

🧠 Review effort: Balanced

Comment on lines +2305 to +2307
if symbol != nil && symbol.CheckFlags&ast.CheckFlagsInstantiated != 0 {
b.ctx.mapper = b.ch.combineTypeMappers(b.ch.valueSymbolLinks.Get(symbol).mapper, oldMapper)
}
Comment on lines +13 to +14
interface Builder<TOutputOut> {
query<T>(resolver: () => T): { output: TOutputOut extends "unset" ? T : TOutputOut };

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

TS 7 declaration emit writes unbound type parameters (TOutputOut, $Output) into .d.ts where 6.0 emits any

2 participants