I'm currently working on deducing the type of an attribute within a generic class.
For instance:
abstract class A<T> {
attr: T;
}
class B extends A<number> {
attr = 1;
}
type Custom = {
value: string;
};
class C extends A<Custom> {
value = "1";
}
const a: A<any> = new B();
const b: A<any> = new C();
const instances: A<any>[] = [a, b];
instances.forEach((instance) => {
// In this case, I am trying to correctly define the type of attr
const attr = instance.attr;
});
Is there a way to achieve this? It's likely that the issue stems from utilizing 'any' to specify the types for a and b.