GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Fix private identifier fields generating errors in class expression declarations by Copilot · Pull Request #62155 · microsoft/TypeScript Conversation
|
There was an error while loading. Please reload this page.
| 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 |
There was a problem 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:
| // 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
…class expressions Co-authored-by: weswigham <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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:
isPrivateIdentifierSymbol() for reliable detectionCopilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
| 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
regression: Private fields appear in type literal in declarations (5.9)
There was an error while loading. Please reload this page.