Skip to content

Preserve inline parameter comments on inferred function types in declaration emit#4160

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-inline-comments-tsgo
Draft

Preserve inline parameter comments on inferred function types in declaration emit#4160
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-inline-comments-tsgo

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 1, 2026

tsc retains inline trailing comments on arrow-function/function-expression parameters in .d.ts output (stripping only the last parameter's, as a side effect of list emit), but tsgo dropped them entirely for inferred types.

export const fn = (
    foo: boolean, // comment on foo
    bar: string, // comment on bar
    buzz: number,  // comment on buzz
) => {};
// before
export declare const fn: (foo: boolean, bar: string, buzz: number) => void;

// after (matches tsc)
export declare const fn: (foo: boolean, // comment on foo
bar: string, // comment on bar
buzz: number) => void;

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 => {}), typeFromFunctionLikeExpression short-circuited to NewPseudoTypeInferred(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 the NoResult short-circuit so the function is always built as a SingleCallSignature (matching TS), preserving parameter source positions; the return type is still serialized from the checker's inferred type.
  • internal/checker/pseudotypenodebuilder.go
    • pseudoParameterToNode: 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 a NoResult return as equivalent (checker supplies it), and strip optional | undefined from the target before resolving its call signature so nested function-expression parameter defaults don't emit spurious TS9013.
  • Test: add 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.

Copilot AI and others added 2 commits June 1, 2026 18:52
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
Copilot AI requested a review from jakebailey June 1, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behavior difference: Inline comment on arrow function parameters is emitted on tsc but not on tsgo

2 participants