I have a module with a number of exported classes which all extend one base class. Each of these classes have a method called getOutput(). These classes match the structure of an API so I cant change it. The API returns a list and in that list can be any one of these classes (expect for the base class). I use the function to get a unified output no matter which type of object it is. The problem is, Typescript wont let you use the class function unless you assign the object to the class first. So in the base class I wrote a switch case to go through all the types and assign the object to a class. See here https://stackblitz.com/edit/angular-nvxmqe-9kxr2k
My problem is that using this approach means that the base class will have to know about each sub class. I would prefer that the subclass itself could assign its class based on the parameters in the class (the type parameter specifically). Or at the very least have another class do a dynamic lookup for the class based on the type. In Java I would use reflection to get a list of classes and assign them that way. I was wondering if there is something similar in Typescript. Or if there was a better way of doing this.
Again, the api is set, I cannot change it.
typein your case. See kaiu-lab.github.io/serializer/classes/serializer.html