Skip to content

Fix declaration emit dropping readonly from as const object literal properties#3933

Merged
jakebailey merged 5 commits into
mainfrom
copilot/fix-tsgo-declaration-emit
May 19, 2026
Merged

Fix declaration emit dropping readonly from as const object literal properties#3933
jakebailey merged 5 commits into
mainfrom
copilot/fix-tsgo-declaration-emit

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

  • Inspect current branch status and recent workflow runs
  • Fetch full history and merge latest origin/main
  • Resolve baseline merge conflict
  • Refresh affected baselines
  • Run targeted declaration emit tests
  • Run required validation commands
  • Run parallel code review and CodeQL validation
  • Reply to actionable PR comment with addressing commit hash

Copilot AI and others added 2 commits May 16, 2026 20:55
…properties

Fix pseudotypenodebuilder to use the ObjectLiteralExpression node instead of the
property name when checking isConstContext. The property name's parent could be a
MethodDeclaration which isConstContext doesn't traverse through, causing readonly
to be dropped from method shorthands and outer properties in as const objects.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/a6a59cb3-682f-426b-8fed-1bddcd23ab2c

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix tsgo declaration emit to retain readonly for method shorthands Fix declaration emit dropping readonly from as const object literal properties May 16, 2026
Copilot AI requested a review from jakebailey May 16, 2026 21:10
@jakebailey jakebailey marked this pull request as ready for review May 16, 2026 22:20
Copilot AI review requested due to automatic review settings May 16, 2026 22:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a declaration emit regression in the Go port where as const object literals could lose readonly on all properties when the first property was a method shorthand, by ensuring const-context detection starts from the object literal node rather than the first property’s name.

Changes:

  • Update pseudo type node building to compute isConst from the containing ObjectLiteralExpression (so method shorthands don’t break const-context propagation).
  • Add a new compiler test + reference baselines covering as const with a method shorthand and nested object property.
  • Update an existing reference baseline (declarationEmitConstObjectLiteralGenericMethod1) to reflect correct readonly + function-type property emission for const object literal methods.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/checker/pseudotypenodebuilder.go Fixes const-context detection for pseudo object literal emission by anchoring the check at the object literal node.
testdata/tests/cases/compiler/declarationEmitReadonlyAsConst.ts Adds regression test reproducing the missing-readonly behavior with a leading method shorthand.
testdata/baselines/reference/compiler/declarationEmitReadonlyAsConst.types Reference type baseline for the new test.
testdata/baselines/reference/compiler/declarationEmitReadonlyAsConst.symbols Reference symbol baseline for the new test.
testdata/baselines/reference/compiler/declarationEmitReadonlyAsConst.js Reference JS + .d.ts baseline verifying readonly properties and function-type method emission.
testdata/baselines/reference/compiler/declarationEmitConstObjectLiteralGenericMethod1.js Updates .d.ts reference output to match corrected readonly/function-type emission for const object literal generic methods.

@jakebailey jakebailey requested a review from weswigham May 18, 2026 15:21
Copy link
Copy Markdown
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

Yep, this looks right - there was just a logic error mismatch between what isConstContext checks and what it was expected to check. It doesn't flow const-ness down into names of declarations, rather it only checks the expression itself, so we need to walk up from name -> member -> expression.

@jakebailey
Copy link
Copy Markdown
Member

@copilot merge main and resolve conflicts and update baselines

Copilot AI and others added 2 commits May 19, 2026 18:05
…aration-emit

# Conflicts:
#	testdata/baselines/reference/compiler/declarationEmitConstObjectLiteralGenericMethod1.js

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/ed38f5e8-6c91-49de-be00-980a2f99f522

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 19, 2026

@copilot merge main and resolve conflicts and update baselines

Merged origin/main, resolved the baseline conflict, refreshed baselines, and reran validation. Addressed in f8bb62d (merge commit 25851eb).

@jakebailey jakebailey requested a review from weswigham May 19, 2026 18:34
Copy link
Copy Markdown
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

Aside: methods and function-typed members have different behavior - adding readonly swapping which one we printback is... probably a very subtle error (say it with me: "function argument bivariance"). We probably need to support readonly on methods properly to fix that.

@jakebailey jakebailey added this pull request to the merge queue May 19, 2026
Merged via the queue into main with commit ab14d13 May 19, 2026
21 checks passed
@jakebailey jakebailey deleted the copilot/fix-tsgo-declaration-emit branch May 19, 2026 21:26
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.

tsgo declaration emit drops readonly from method shorthands and outer properties in as const object literal

4 participants