Preserve inline parameter comments on inferred function types in declaration emit#4160
Draft
Copilot wants to merge 3 commits into
Draft
Preserve inline parameter comments on inferred function types in declaration emit#4160Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix behavior difference in inline comments for tsgo
Preserve inline parameter comments on inferred function types in declaration emit
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tscretains inline trailing comments on arrow-function/function-expression parameters in.d.tsoutput (stripping only the last parameter's, as a side effect of list emit), buttsgodropped them entirely for inferred types.Root cause
Declaration emit for inferred types uses the pseudochecker (port of TS's
expressionToTypeNode). For an arrow with an un-inferrable return (e.g. empty body=> {}),typeFromFunctionLikeExpressionshort-circuited toNewPseudoTypeInferred(node), discarding the syntactically-built parameters. They were then rebuilt fully synthesized by the checker with no source range, so the printer had no positions from which to emit trailing comments.Changes
internal/pseudochecker/lookup.go— Drop theNoResultshort-circuit so the function is always built as aSingleCallSignature(matching TS), preserving parameter source positions; the return type is still serialized from the checker's inferred type.internal/checker/pseudotypenodebuilder.gopseudoParameterToNode: copy the original parameter declaration's range onto the synthesized node (guarded to the enclosing file) so the printer emits trailing comments.pseudoTypeEquivalentToType(single-call-signature case): treat aNoResultreturn as equivalent (checker supplies it), and strip optional| undefinedfrom the target before resolving its call signature so nested function-expression parameter defaults don't emit spuriousTS9013.declarationEmitArrowParameterComments.ts.Baseline impact
isolatedDeclarationErrorsReturnTypes: 59 → 31 errors, now exactly matching TS (triaged diff removed).commentsFunction(es2015): now preserves JSDoc parameter comments (accepted diff removed).isolatedDeclarationErrors: error count now matches TS.