What is the proper way to define a list of objects that extend another class using generics?
I am looking for a solution where I can declare something like "anything that extends A", without specifying a specific generic type for each object.
// valid abstract class
abstract class A<SOME_TYPE> {
private something: SOME_TYPE;
constructor(xxx: SOME_TYPE) {
console.log(xxx);
}
}
// valid class
class B extends A<number> {}
// How do I create a list of objects that extend A?
const listOfObjects: Record<string, A<any>> = {
b: B, // TS2741 error
};
// Attempted solutions that didn't work:
const listOfObjects: Record<string, typeof A> = {
b: B, // Type 'typeof B' is not assignable to type 'typeof A'
};
Using TypeScript version 4.4.4