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

231
Views
JSDoc: ¿cómo insinuar this.constructor.staticSomething?

Estoy llamando a un método estático del constructor de una clase javascript anónima usando this.constructor.coords() , pero el tipo devuelto no se reconoce correctamente. Se trata como any .

Sé que puedo lanzarlo simplemente lanzarlo manualmente como {x: number; y: number;}[] , pero me pregunto si hay una forma más inteligente de hacer que VSCode/JSDoc solo tenga en cuenta que el tipo de this.constructor.something debe ser el del método o propiedad estática correspondiente. Alternativamente, me pregunto si es posible en JSDoc convertir this.cls = this.constructor con el tipo de clase anónimo (sin darle un nombre), porque eso también resolvería el problema de this.constructor.something .

 MyAnonymousClass = class { static coords(){ return [{x:0, y:1}, {x:1, y:0}, {x:-1, y:-1}]; } /* type of coords (on mouse hover in vsCode): (method) MyAnonymousClass.coords(): { x: number; y: number; }[] */ // (CORRECT) constructor(){ const x = this.constructor.coords(); // type of x (on mouse hover in vsCode): any // (INCORRECT) } } AnotherAnonymousClass = class extends MyAnonymousClass{ static coords(){ return [{x:0, y:2}, {x:-2, y:0}]; } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Lo siguiente debería hacer el truco. Acabo de envolver la declaración de clase alrededor de un IIFE para que nunca sea accesible desde el exterior. Es como una clase anónima.

 const MyAnonymousClass = (() => { return class _ { static coords() { return [{ x: 0, y: 1 }, { x: 1, y: 0 }, { x: -1, y: -1 }]; } constructor() { const x = /** @type {typeof _} */(this.constructor).coords(); } foo() { } } })(); const AnotherAnonymousClass = class extends MyAnonymousClass { static coords() { return [{ x: 0, y: 2 }, { x: -2, y: 0 }]; } }

Captura de pantalla

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!