class A {
public static find(): Query{
const f = () => new this();
return new Query(f);
}
}
class B extends A {
}
class C extends A {
}
class Query {
private readonly entity: () => A;
constructor(entity: () => A) {
this.entity = entity
}
public someMethod():???? {
return this.entity()
}
}
This snippet resembles the concept of ActiveRecords. I am unsure about how to define the return type for Query.someMethod(). Setting it as A would restrict us from using child classes as types, leading to errors like in the following scenario:
const monkey: C = C.find().someMethod()
This would result in a type error. If you have insights on handling such cases in TypeScript, kindly provide suggestions with care and consideration.