Mi caso es que una biblioteca javascript usa el método mixin para crear un objeto. Digamos que es un coche. En js, códigos como
function Car( yourInjectObject ){ Mixin(this, yourInjectObject) } Car.prototype.Run = function (){ ... }Ahora en car.d.ts
class Car{ Run(){ ... } }Ahora, si quiero escribir mi injectObject, siempre debo declarar una interfaz
interface IMyInject extends Car{ someVar:number Func1(){} Func2(){} //Func3(){} // no Func3 declare } let injectObject = { someVar: 0, Func1(this: IMyInject ){ this.Run() // ok this.Func2() // ok this.Func3() // type error, Func3 not declared }, Func2() { // if I forgot add a this declare this.Run() // type error this.Func3() // type error, no declare of this.Func1() // type error }, Func3(this: IMyInject ){ // this.Run() // ok this.Func1() // ok this.Func2() // ok this.Func3() // type error, }, } let mycar = new Car(injectObject)¿Es posible facilitar los códigos, sin predeclarar una interfaz? Sugerir:
let myInject = MixIn<Car>{ someVar:1, Func1(){ this.someVar =2; this.Run() this.Func2() }, Func2(){ this.Run() this.Func1() } } let myCar = new Car(myInject)