-
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
Stronger 'this' warnings - suggestion #18436
Comments
See #513 |
It is worth mentioning that another option is to simply avoid Honestly, without experimental and prospective features like decorators, classes in TS/ES have relatively weak expressive power compared to plain old functions and object literals. |
@aluanhaddad well, while I think the point is, almost all of the issues related to class Foo {
value: string;
constructor(target: HTMLElement) {
this.value = 'bar';
target.addEventListener('click', this.onclick);
}
onclick() {
console.log(this.value);
}
}
const button = document.createElement('button');
button.innerHTML = 'Click Me!';
document.body.appendChild(button);
const foo = new Foo(button); When you click on the button, you won't get |
@kitsonk you are of correct. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Would it be possible to add (or did I miss an already open issue regarding) support for a stronger
this
assertion?Coming from strongly typed languages I have to say that worrying about the
this
context adds a lot of noise to coding.I've read
this
in typescript wiki page and it helps identifying the issue a lot, but I really don't feel safe coding when this issue is only identified in runtime.The wiki page suggests red flags for
this
issues, is there a chance of requesting this support by the compiler? Some strict mode flag that makes the compiler merely identify places that instance methods are passed by reference instead of invoked and place a warning/error?The text was updated successfully, but these errors were encountered: