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

155
Views
Typescript generic interface with field that references the generic class (not instance) type

Let's say I have a typescript class A, and a class B that extends A

class A {
  static a(): number { return 10; }
  a_(): number { return 10; }
}

class B extends A {
  static b(): number { return 20; }
  b_(): number { return 20; }
}

I would like to define a generic typescript interface, like so:

interface ClassAndInstance<C extends A> {
  c: ClassType<C>
  i: C
}

(Note: ClassType here refers to the class (not instance) of the generic type.)

Now, if I have an instance of the ClassAndInstance

ci: ClassAndInstance<B>;

I want to be able to call both the class and the instance fields of B, like so:

ci.c.a();  // 10
ci.c.b();  // 20
ci.i.a_(); // 10
ci.i.b_(); // 20;

How would I define ClassType to achieve this in a type safe manner?

I've chosen an interface to define the semantics behind ClassAndInstance, but if there's any other way of achieving this, that would work too.

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!