Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static block on unnamed class produces invalid javascript #60879

Open
IanSSenne opened this issue Dec 30, 2024 · 0 comments · May be fixed by #60886
Open

static block on unnamed class produces invalid javascript #60879

IanSSenne opened this issue Dec 30, 2024 · 0 comments · May be fixed by #60886
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@IanSSenne
Copy link

IanSSenne commented Dec 30, 2024

🔎 Search Terms

  • class
  • invalid
  • codegen
  • static

🕗 Version & Regression Information

  • This changed after version 4.4
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about classes, static members of classes
  • I was unable to test this on prior versions because static blocks where introduced in typescript 4.4

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20241229#code/KYDwDg9gTgLgBAE2AMwIYFcA28DGnUDOBA3gFBwVwEyowCWOiwAthAFwB26zARsFAG5ylarQZwylKXBgALOgQB0SVnAC8cAIxCpAX1K6gA

💻 Code

export default class{
    static demo:number;
    static {
        this.demo = 1;
    }
}

🙁 Actual behavior

TypeScript produces an invalid output where the code references an undefined default_1
I'm assuming the empty class is meant to be assigned to this.

example output:

var _a;
class {
}
_a = default_1;
(() => {
    _a.demo = 1;
})();
export default default_1;

🙂 Expected behavior

I would expect typescript to assign the class to the generated d

Additional information about the issue

TypeScript has been exhibiting this behavior since support for static blocks was introduced as far as I can tell, prior to version 4.4.4 in the playground produces a different set of invalid code where it just moves the block outside of the class with no modification.

this still technically happens without the export default but typescript does have a warning.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Jan 2, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
2 participants