Skip to content

Properly emit super not root statement errors with class fields - #54475

Closed
Joshua Chen (Josh-Cena) wants to merge 7 commits into
microsoft:mainfrom
Josh-Cena:fix-super-not-statement
Closed

Joshua Chen (Josh-Cena) wants to merge 7 commits into
microsoft:mainfrom
Josh-Cena:fix-super-not-statement

Conversation

@Josh-Cena

Copy link
Copy Markdown
Contributor

Fixes #54445

I've:

  • Made parameter properties + no-root-super always an error
  • Made private fields + no-root-super not an error, if private fields won't be downleveled

@typescript-bot TypeScript Bot (typescript-bot) added the For Backlog Bug PRs that fix a backlog bug label May 31, 2023
@Josh-Cena
Joshua Chen (Josh-Cena) force-pushed the fix-super-not-statement branch 2 times, most recently from d716d8f to a3f8645 Compare June 1, 2023 03:37
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
Comment thread src/compiler/checker.ts Resolved
~~~~~~~~~~~~
}
~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this an intended consequence of this change?

@Josh-Cena Joshua Chen (Josh-Cena) Jun 12, 2023 •

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.

Yes, because it's a duplicate report. Specifically, all test cases where this or super is referenced before super() remain a TS17009/TS17011 error, while TS2376 is now emitted strictly when the downlevel emission is going to cause this to be implicitly referenced.

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

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

TS2401 does not work with "target": "ESNext"

3 participants