Trying to incorporate Backbone's Events properties into a TypeScript class has hit a roadblock. Here's what I'm encountering...
class Foo {
constructor () {
_.assign(this, Backbone.Events); // or _.extend()
this.stopListening(this.otherInstance);
}
}
let bar = new Foo();
bar.on("myevent", handler);
The problem arises when these compile time errors show up:
Error TS2339: Property 'stopListening' does not exist on type 'Foo'.
Error TS2339: Property 'on' does not exist on type 'Foo'.
I'm not well-versed in how TypeScript deals with this issue, but it seems like something that should be manageable.
Note: searching for a solution that can easily be implemented across multiple classes requiring Backbone.Events
functionality (i.e. avoiding the repetition of copying/pasting all the on, off, listenTo...
methods, or using some complex proxy approach).
Given that Backbone.Events is simply an object, traditional ES6 syntax won't allow me to extend it. For example:
class Foo extends Backbone.Events {}
Any suggestions?