// Greetings from the TypeScript Playground, a platform where you can experiment with TypeScript code.
type Constructor<T> = new (...args: any[]) => T;
class ServiceChecklistResponse {
}
class AnotherModel {
}
abstract class AbstractView {
getJsonDataModelRef<T>() : Constructor<T> | null
{
return null;
}
getAnotherDataModel<T>(): Constructor<T> | null
{
return null;
}
}
class testView extends AbstractView {
getJsonDataModelRef<ServiceChecklistResponse>() : Constructor<ServiceChecklistResponse> | null {
return ServiceChecklistResponse;
}
getAnotherDataModel<AnotherModel>() : Constructor<AnotherModel> | null
{
return AnotherModel;
}
}
Type 'typeof ServiceChecklistResponse' is not assignable to type 'Constructor<ServiceChecklistResponse>'.
Type 'ServiceChecklistResponse' is not assignable to type 'ServiceChecklistResponse'. Two different types with this name exist, but they are unrelated.
'ServiceChecklistResponse' could be instantiated with an arbitrary type which could be unrelated to 'ServiceChecklistResponse'.
Type 'typeof AnotherModel' is not assignable to type 'Constructor<AnotherModel>'.
Type 'AnotherModel' is not assignable to type 'AnotherModel'. Two different types with this name exist, but they are unrelated.
'AnotherModel' could be instantiated with an arbitrary type which could be unrelated to 'AnotherModel'.
Can someone please explain why this issue is happening and suggest how it can be resolved? It is necessary for it to return a class reference because a controller will utilize it later on.
const Model = myView.getJsonDataModelRef()
const foo = new Model()