Typescript: Type declaration inheritance with classes

Question about Typescript

If we have 2 different classes A and B that share 77 property-type declarations, but not the methods (including the constructor):

class A {
 public p1:number
 public p2: string
 public p77:"hello";
 this.p1 = 5

class B {
 public p1:number;
 public p2:string;
 public p77:number
 public p78: number
//... more properties
// they set properties in a different way

Is there any way to use the first 77 properties type declarations from class A in class B?

class B extends A  {
  someMethod() {
    return super.p1;


Something with that many properties (& properties can be functions as well, so it’s more than that) is completely unmanageable – that seems like a fundamental issue. I can’t see how that is going to be useful, or how you’re not essentially making it impossible to program against

What do you mean? This are properties from a physical device, I don’t think there is any problem in that sense.

But why do you need it in a class, and why are you then inheriting from that into another class? It’s like tracking 77 mutable global variables (then that multiplied out because you’re then accessing them via other child classes) – it seems crazy. How can you possibly hold that program in your head, or validate that the program is correct?

I realize I can’t see the exact usecase, but if you have some data from physical device, why not just use that data?

Most C programs for File formats have a header struct defining about 40 different variables, particularly meta-parameters about the file: the length, the type of data, how many blocks they have, etc.

When you parse in Python or NodeJS a file from such a format, you ideally form the same structure, so there is a clear correspondence.

In this case, the file format has 2 different versions, they have the same keys but because they are 10 years apart, there are many internal differences.

I don’t find that crazy at all, but who knows.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.