HTMLElement onchange should use `this: this`
This example worked in 2.0, but not in 2.1:
const input = document.createElement('input');
input.value; // OK
input.onchange = function() {
this.value; // Error
}
The current definition for onchange in HTMLElement is: onchange: (this: HTMLElement, ev: Event) => any;. Maybe it should use this: this?
Duplicate of https://github.com/Microsoft/TypeScript/issues/12490
I broke this with my change https://github.com/Microsoft/TSJS-lib-generator/pull/166 to reduce instantiations in the library, by making less types generic (types using this are implicitly generic with respect to this).
The fix here is to generate onChange events for the type hierarchy with the correct type, instead of putting in the parent with type this.
If I'm reading it right, Microsoft/TypeScript#14141 may fix this by setting the this type of the function to the type of input.
If I'm reading it right, Microsoft/TypeScript#14141 may fix this by setting the this type of the function to the type of input.
correct.
Given that https://github.com/Microsoft/TypeScript/pull/14141 has now been merged, what is left to do to fix this issue and https://github.com/Microsoft/TypeScript/issues/12490?
I note that with with 2.3.0-dev.20170315 and noImplicitThis the following still types incorrectly (per https://github.com/Microsoft/TypeScript/issues/12490):
let i = new Image();
i.onload; // HTMLElement.onload: (this: HTMLElement, ev: Event) => any
The fix here is to generate onChange events for the type hierarchy with the correct type, instead of putting in the parent with type this.
This won't help custom elements, and probably will generate much longer library file. (60+ lines per one HTMLElement interface, 80+ HTMLElements = 4800+ more lines)
Given that Microsoft/TypeScript#14141 has now been merged, what is left to do to fix this issue and Microsoft/TypeScript#12490?
The PR explicitly says that it works only on --noImplicitAny so I think it's not applicable to this issue.
Hello @saschanaz
I have created a solution for this.
The solution is to specifically update in the emitter to replace GlobalEventHandlers to this. I have already tested my solution, and it worked.
I can open a pr for it
Please take a look of https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/195#issuecomment-280722380 and https://github.com/microsoft/TypeScript/issues/12490, it was done and reverted because of performance regression.
Please take a look of #195 (comment) and microsoft/TypeScript#12490, it was done and reverted because of performance regression.
Do you have another solution to propose?