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

class property inference in constructors not working #50972

Closed
trusktr opened this issue Sep 27, 2022 · 3 comments
Closed

class property inference in constructors not working #50972

trusktr opened this issue Sep 27, 2022 · 3 comments

Comments

@trusktr
Copy link
Contributor

trusktr commented Sep 27, 2022

Bug Report

According to this feature we should be able to define properties inside constructors.

🔎 Search Terms

class property inference in constructor not working

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

💻 Code

class Foo {
  constructor() {
    this.greeting = 'hello!'; // ERROR
  }
}
var x = new Foo();
console.log(x.greeting); // ERROR

🙁 Actual behavior

TS does not recognize that the property exists

🙂 Expected behavior

TS should recognize that the property exists

@MartinJohns
Copy link
Contributor

MartinJohns commented Sep 27, 2022

According to this feature we should be able to define properties inside constructors.

It does work, but your playground is incorrectly set to TypeScript, not JavaScript. This is currently a JavaScript only feature (the issue title mentions JavaScript). TypeScript support is tracked at #12613.

@trusktr
Copy link
Contributor Author

trusktr commented Sep 27, 2022

I see! That's unexpected that the same code behaves differently based on file type.

@trusktr
Copy link
Contributor Author

trusktr commented Sep 27, 2022

I see! That's unexpected that the same code behaves differently based on file type. I'd expect the difference to be type annotations or no type annotations, but not different forms of type inference.

@trusktr trusktr closed this as completed Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants