Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
¿Hay alguna manera en mecanografiado para declarar el tipo de esto al definir un objeto literal?

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)
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!