Skip to content

Allow global Symbol computed names during pseudochecker object literal serialization - #3297

Closed
Mateusz Burzyński (Andarist) wants to merge 2 commits into
microsoft:mainfrom
Andarist:fix/id-definitely-symbol-methods
Closed

Allow global Symbol computed names during pseudochecker object literal serialization#3297
Mateusz Burzyński (Andarist) wants to merge 2 commits into
microsoft:mainfrom
Andarist:fix/id-definitely-symbol-methods

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

This change matches Strada's behavior more closely

export const symbolNamed = {
[Symbol.toStringTag]: "demo",
[Symbol.iterator]() {
return [1, 2, 3][Symbol.iterator]();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In Strada, this reports a slightly different error (TS playground):

Method must have an explicit return type annotation with --isolatedDeclarations.

expression := e.Name().Expression()
if !ast.IsPrimitiveLiteralValue(expression, false) {
if !ast.IsPrimitiveLiteralValue(expression, false) &&
!ch.isDefinitelyReferenceToGlobalSymbolObject(expression) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not super fond of coupling the pseudochecker with a checker's method like this but this is kinda the earliest moment at which this thing can be checked without doubling the work somewhere else.

I tried putting this in the nodebuilder but that had its own issues and was allowing all computed properties in the pseudochecker, just so the nodebuilder could reject them

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd go so far as to say it's a bad idea that goes against the premise of the ID pseudochecker. The functionality needs to be implementable without a full check to be consistent with ID's goals.

@weswigham Wesley Wigham (weswigham) Mar 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fortunately, it seems like isDefinitelyReferenceToGlobalSymbolObject seems like it's not too bad to implement an equivalent outside the checker? You just need the binder's reference resolver instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You just need the binder's reference resolver instead.

I actually had this on #4902 but deleted it; I should have remembered this thread, oops

@RyanCavanaugh

Copy link
Copy Markdown
Member

Thank you for contributing to the TypeScript native port!

Development has moved from this repository back to the main microsoft/TypeScript repository. GitHub does not have PR transfer functionality, so we're closing this PR here.

If this change is still relevant, please reopen it as a new pull request in microsoft/TypeScript. We'd appreciate your help carrying the contribution over, and we apologize for the extra work.

See microsoft/typescript-go#4918 for more information about the move.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No linked issue This PR doesn't say what bug it fixes Unmigrated PR This PR was open at the time of the repo move back to TypeScript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants