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

112
Views
Cómo hacer que el tipo de miembro estático de una clase apunte al tipo de la subclase
class SingletonBaseClass { static singleton: SingletonBaseClass | null = null; static instance() { if (!this.singleton) { this.singleton = new this(); } return this.singleton; } static destroy() { this.singleton = null; } } class Demo extends SingletonBaseClass { hello() { } } Demo.instance().hello();

Arriba está el código, Demo.instance() se considerará una instancia de SingletonBaseClass en lugar de Demo , por lo que Demo.instance().hello() informará un error de TypeScript.

¿Hay alguna forma de hacer que el tipo de retorno de Demo.instance() sea SingletonBaseClass ?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

podrías lanzarlo:

 (Demo.instance() as Demo).hello();
about 4 years ago · Santiago Gelvez 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!