-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 from constructor does not work with private class fields #39960
Comments
@orta That's not what I was referring to. I was referring to this recently released behavior which currently behaves correctly for non-private fields. The playground that is linked demonstrates the bug without need for modification. |
Yep, I know what you're talking about 👍🏻 My point was that that syntax space is already taken for the implicit field which is created how it currently works. We'd have to add support for putting |
I'm afraid I don't really understand what you mean. The playground I linked doesn't use any TypeScript-specific syntactic sugar. Are you referring to parameter properties? // no implicit field created
constructor(test: number) { }
// implicit field created
constructor(public test: number) { } Except for the one type annotation, the playground I linked is valid vanilla JS so I don't really understand what that has to do with what is or isn't valid in the constructor's params. Here's another demonstration that's maybe more clear. class Example {
#test; // should not be implicit any error
constructor() {
this.#test = 42;
}
} |
This works with no errors in class Example {
test;
constructor(test: number) {
this.test = test;
}
get publicTest() {
return this.test
}
} But the original example code doesn't. That should be fixed. |
@ahejlsberg think this would be trivial to fix before the 4.0 stable? |
TypeScript Version: 4.0.0-dev.20200803
Search Terms: class property inference, private class fields
Expected behavior: private class field's type is inferred from its assignment in the constructor
Actual behavior: typechecker reports implicit
any
for private class fieldRelated Issues:
Code
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: