extending a class with a generic T

Viewed 1940

In TypeScript is there a way to extend a class with a generic type? Refer to my "hypothetical scenario" example where I want my class to have property called "breed" (or whatever):

interface dog {
  breed: string;
}

export class animal<T> extends T {
  legs: number;
}

export class main {
  private mydog: animal = new animal<dog>();

  constructor() {
    this.mydog.legs = 4;
    this.mydog.breed = "husky"; //<-- not conventionally possible, but basically want to acheive this
  }
}
1 Answers
Related