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

194
Views
In Typescript, is it possible to override a superclass property's type without overriding the value?

I have a superclass property with a generic type, e.g.:

class Super {
  static get foo(): Record<string, any> {
    return ...
  }
}

I thought I could override the type like this:

class Sub extends Super {
  static foo: SubType;
}

However, this sets Sub.foo to undefined. I want Sub.foo to maintain the same value, but have a new type. Is this possible?

The type for Sub.foo is different because Super.foo depends on other static properties of the subclass.

I think implementing an interface should work, but it'll be good to know if there's another way.

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

0

Use declare to avoid compiling the variable into the actual Javascript:

class Sub extends Super {
  declare static foo: SubType;
}
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!