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

100
Views
Mezclas de TypeScript y nombres de constructores

Tengo esta muestra de código experimentando con mixins en TypeScript. Sin embargo, no está devolviendo lo que esperaba.

Debería darme: User ({"id":3,"name":"Lorenzo Delaurentis"}) .

En cambio, obtengo: Function ({"id":3,"name":"Lorenzo Delaurentis"}) .

La línea let Name = Class.constructor.name debería darme User , pero no lo es. ¿Me estoy perdiendo algo obvio aquí?

 type ClassConstructor<T> = new(...args: any[]) => T function withDebug<C extends ClassConstructor<{ getDebugValue(): object }>>(Class: C) { return class extends Class { constructor(...args: any[]) { super(...args) } debug() { let Name = Class.constructor.name let value = this.getDebugValue() return `${Name} (${JSON.stringify(value)})` } } } class DebugUser { constructor( private id: number, private firstName: string, private lastName: string ) {} getDebugValue() { return { id: this.id, name: `${this.firstName} ${this.lastName}` } } } let User = withDebug(DebugUser) let user = new User(3, 'Lorenzo', "Delaurentis") console.log(user.debug())

PD Compilé con tsc mixins --target ES6 . De lo contrario, aparece un error: error TS2339: Property 'name' does not exist on type 'Function'.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solo quieres Class.name . El Class.constructor es Function .

about 4 years ago · Juan Pablo Isaza Report
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!