Open davisford opened 3 years ago
Just out of curiosity, is there a specific reason to have the first parameter to the oninputreport
method at all? The HIDInputReportEvent
object itself has a reference to the HIDDevice
, so it seems redundant / un-necessary.
this
has special meaning in typescript.
additionally, oninputreport is a property and not a method. you'd probably want to do MySubclass: ctor { this.addEventListener('inputreport', this._onInputReport.bind(this)) }
This is a TypeScript project bootstrapped with
create-react-app
, here are my imports:Here is my
tsconfig.json
The issue appears to be the declaration of the
oninputreport
function on theHIDDevice
class as such:Using
this
here seems to constrain the function to force it to be implemented either onHIDDevice
or else if implemented on another class it forces it to usethis
as the parameter name, which causes other problems...here's an example of what I mean:Note above the TS compiler is complaining that my implementation of that function is not assignable b/c the parameter name is not matching. I attempted to underscore it, but it still does not like it:
So, I tried to override it using a
typings
file, but that still isn't working. The only hack workaround at this point is to cast it tounknown
and then cast it back which is realistically a very poor hack.Of course, if I name the parameter
this
in my function implementation, well this causes me other issues:I can no longer use
this
as intended on my own class.The fix here seems fairly simple. In the spec / implementation of the typings, you could re-do the declaration like so:
I see several other areas of the typings spec where
this
is used quite a bit. I would advise against this if possible.