GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix private identifier fields generating errors in class expression declarations by Copilot · Pull Request #62155 · microsoft/TypeScript

Conversation

Copilot AI commented Jul 31, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR fixes a regression introduced in TypeScript 5.9 where private fields using ECMAScript syntax (#field) were being silently excluded from class expression type literals in declaration files, while traditional private/protected fields generated proper error messages.

Issue

When compiling a class expression with private fields to a declaration file, the behavior was inconsistent:

// Source code
export const ClassExpression = class {
    private traditionalPrivate = 0;  // Generated error TS4094
    #ecmaScriptPrivate = 1;          // Silently excluded, no error
    public value = 2;
};

This inconsistency meant that ECMAScript private fields could potentially slip through without proper validation.

Root Cause

The createTypeNodesFromResolvedType function in checker.ts had inconsistent handling for class expressions converted to type literals (WriteClassExpressionAsTypeLiteral flag):

  • Traditional private/protected fields: Generated error but continued processing
  • ECMAScript private identifier fields: Silently skipped with continue

Solution

Updated the implementation to treat both types of private fields consistently by:

  1. Using isPrivateIdentifierSymbol() for reliable detection of ECMAScript private fields
  2. Generating the same error message for both traditional and ECMAScript private fields: "Property '{field}' of exported anonymous class type may not be private or protected"
  3. Removing the silent skip behavior to ensure consistent error reporting
// Before: Inconsistent behavior
if (getDeclarationModifierFlagsFromSymbol(propertySymbol) & (ModifierFlags.Private | ModifierFlags.Protected)) {
    // Generate error for traditional private/protected
}
if (isPrivateIdentifier(propertySymbol.valueDeclaration.name)) {
    continue; // Silent skip for ECMAScript private fields
}

// After: Consistent behavior  
if (getDeclarationModifierFlagsFromSymbol(propertySymbol) & (ModifierFlags.Private | ModifierFlags.Protected)) {
    // Generate error for traditional private/protected
}
if (isPrivateIdentifierSymbol(propertySymbol)) {
    // Generate same error for ECMAScript private fields
}

Result

Both types of private fields now generate consistent error messages, ensuring:

  • Proper validation of all private members in class expressions
  • Consistent developer experience regardless of private field syntax
  • Prevention of invalid TypeScript syntax in declaration files

The fix maintains existing behavior for traditional private fields while bringing ECMAScript private fields in line with the same error reporting standards.

Fixes #62153.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Initial plan
49bfe02
Copilot AI assigned Copilot and Ryan Cavanaugh (RyanCavanaugh) Jul 31, 2025
Copilot started work on behalf of Ryan Cavanaugh (RyanCavanaugh) July 31, 2025 15:00
View session
Copilot AI and others added 2 commits July 31, 2025 15:21
@RyanCavanaugh
Fix private fields appearing in class expression type literals
d30b0df
Co-authored-by: RyanCavanaugh <[email protected]>
@RyanCavanaugh
Update baselines and format fixes for private field declaration fix
95a3539
Co-authored-by: RyanCavanaugh <[email protected]>
Copilot AI changed the title [WIP] regression: Private fields appear in type literal in declarations (5.9) Fix private fields appearing in type literals in declarations Jul 31, 2025
Copilot AI requested a review from Ryan Cavanaugh (RyanCavanaugh) July 31, 2025 15:27
Copilot finished work on behalf of Ryan Cavanaugh (RyanCavanaugh) July 31, 2025 15:27
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) assigned Wesley Wigham (weswigham) and unassigned Ryan Cavanaugh (RyanCavanaugh) Jul 31, 2025
weswigham
Wesley Wigham (weswigham) requested changes Jul 31, 2025
View reviewed changes
Comment thread src/compiler/checker.ts Outdated
if (getDeclarationModifierFlagsFromSymbol(propertySymbol) & (ModifierFlags.Private | ModifierFlags.Protected) && context.tracker.reportPrivateInBaseOfClassExpression) {
context.tracker.reportPrivateInBaseOfClassExpression(unescapeLeadingUnderscores(propertySymbol.escapedName));
}
// Skip ECMAScript private identifier fields (e.g., #field) in class expression type literals

@weswigham Wesley Wigham (weswigham) Jul 31, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nope. This should be an error here, like a private. This is also much more verbose than needed. Try this instead:

Suggested change
// Skip ECMAScript private identifier fields (e.g., #field) in class expression type literals
if (isPrivateIdentifierSymbol(propertySymbol) && context.tracker.reportPrivateInBaseOfClassExpression) {
context.tracker.reportPrivateInBaseOfClassExpression(idText((propertySymbol.valueDeclaration! as NamedDeclaration).name! as PrivateIdentifier));
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

Copilot AI Jul 31, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Applied your suggestion! The implementation now uses isPrivateIdentifierSymbol and generates the same error as traditional private/protected fields instead of silently skipping them. This makes the behavior much more consistent and provides proper error reporting. Commit: b8ca24c

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot started work on behalf of Wesley Wigham (weswigham) July 31, 2025 19:24
View session
@weswigham
Apply @weswigham's suggestion: Generate errors for private fields in …
b8ca24c
…class expressions

Co-authored-by: weswigham <[email protected]>
weswigham
Wesley Wigham (weswigham) approved these changes Jul 31, 2025
View reviewed changes
Copilot AI changed the title Fix private fields appearing in type literals in declarations Fix private identifier fields generating errors in class expression declarations Jul 31, 2025
Copilot AI requested a review from Wesley Wigham (weswigham) July 31, 2025 19:36
Copilot finished work on behalf of Wesley Wigham (weswigham) July 31, 2025 19:36
Wesley Wigham (weswigham) and others added 2 commits July 31, 2025 14:25
@weswigham
Merge branch 'main' into copilot/fix-62153
d3ed886
@typescript-bot
Update Baselines, Applied Lint Fixes, and/or Formatted
2543e40
@weswigham
Wesley Wigham (weswigham) marked this pull request as ready for review July 31, 2025 22:18
Copilot AI review requested due to automatic review settings July 31, 2025 22:18
Copilot AI reviewed Jul 31, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a regression in TypeScript 5.9 where ECMAScript private fields (#field) in class expressions were silently excluded from declaration files, while traditional private/protected fields properly generated error messages. The fix ensures consistent error reporting for both types of private members in exported anonymous class types.

Key changes:

  • Added proper error reporting for ECMAScript private identifier fields in class expressions
  • Updated the type checker to use isPrivateIdentifierSymbol() for reliable detection
  • Ensured both traditional and ECMAScript private fields generate the same TS4094 error

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/compiler/checker.ts Added error reporting logic for ECMAScript private identifier fields in class expressions
tests/cases/compiler/privateFieldsInClassExpressionDeclaration.ts New test case covering both instance and static private fields
tests/baselines/reference/privateFieldsInClassExpressionDeclaration.errors.txt Expected error output showing consistent TS4094 errors for all private fields
tests/baselines/reference/privateFieldsInClassExpressionDeclaration.js Expected JavaScript compilation output
tests/baselines/reference/privateFieldsInClassExpressionDeclaration.types Expected type information output
tests/baselines/reference/privateFieldsInClassExpressionDeclaration.symbols Expected symbol information output

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/checker.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

weswigham
Wesley Wigham (weswigham) approved these changes Jul 31, 2025
View reviewed changes
gabritto
Gabriela Araujo Britto (gabritto) approved these changes Jul 31, 2025
View reviewed changes
@weswigham Wesley Wigham (weswigham) mentioned this pull request Jul 31, 2025
Intentionally regress one buggy declaration output to an older version #62163
Merged
@weswigham
Wesley Wigham (weswigham) merged commit 39c5d01 into main Jul 31, 2025
@weswigham
Wesley Wigham (weswigham) deleted the copilot/fix-62153 branch July 31, 2025 22:51
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Feb 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@weswigham Wesley Wigham (weswigham) weswigham approved these changes
@gabritto Gabriela Araujo Britto (gabritto) gabritto approved these changes
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) Awaiting requested review from RyanCavanaugh

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@weswigham Wesley Wigham (weswigham)

Copilot code review Copilot

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

regression: Private fields appear in type literal in declarations (5.9)

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@weswigham @gabritto @RyanCavanaugh @typescript-bot
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.