-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Readonly vars getting typecast to "false" instead of "boolean" #13113
Comments
class blah {
private readonly _something: boolean;
constructor() {
this._something = true;
}
}
|
I guess "by design" is an answer. Not an answer I'd expect for this, but fair enough. |
Can I ask why there are two initializers for |
Because _something has a default value, and only some paths in the initializer set it. It was an easy fix to change it to "private readonly _something: boolean = false", it just seems an odd language construct. Readonly is only readonly after the end of the constructor. If anything, it feels like you should take the type as the union of all options set in the validity period, so in this case would be false|true. |
Duplicate of #12148. |
TypeScript Version: 2.1.4
Code
Expected behavior:
Doesn't cause an error
Actual behavior:
Causes an error
The text was updated successfully, but these errors were encountered: