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

"useDefineForClassFields" compiles invalid code which fails at runtime. #57543

Closed
AlexanderFarkas opened this issue Feb 26, 2024 · 2 comments
Closed
Assignees
Labels
Duplicate An existing issue was already created Needs Investigation This issue needs a team member to investigate its status.

Comments

@AlexanderFarkas
Copy link

AlexanderFarkas commented Feb 26, 2024

🔎 Search Terms

"useDefineForClassFields" "vite" "esbuild" "invalid initialization order" "property initializers are executed before constructor initializers"

🕗 Version & Regression Information

Version 5.3.3, tried 5.4-beta with the same bug.

⏯ Playground Link

https://www.typescriptlang.org/play?useDefineForClassFields=true&target=99&resolvePackageJsonImports=false&ts=5.3.3#code/LAKAxgNghgzjAEBBeBvU95gPYDsYBcAnAVzHy0IAoAHQgSwDcp8BTeKALlSgFstic+LjmI8ARi0IBfAJSp0GTLhhYILAHQQsAc0r4AFnRjqwMgNwKpoBdpb54YynLQhF8QneKEcGA0fVQAXwC+Bau8FYgCmDCohKE8AC88H7GYvAAVPAAzGGRoDgsAO5IlCi8-IJc2bJmQA

💻 Code

class A {
  constructor(private a: {amount: number}) {
    console.log(this.c);
  }

  get b() {
    return  this.a.amount;
  }

  c: number = this.b * 3;
}

new A({amount: 3});

🙁 Actual behavior

When I run the code, it fails with

[ERR]: Cannot read properties of undefined (reading 'amount') 

🙂 Expected behavior

Code shouldn't compile

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

Related: #55132

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Feb 26, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.5.0 milestone Feb 26, 2024
@rbuckton rbuckton added the Duplicate An existing issue was already created label Feb 28, 2024
@rbuckton
Copy link
Member

This is a duplicate of #55132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

4 participants