I get the current error:
Uncaught ReferenceError: can't access lexical declaration 'AbstractClass' before initialization
when doing this in a new Angular project:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = '';
ngOnInit() {
console.log(JSON.stringify(new (AbstractClass.get("MyId1"))()))
}
}
And I can not see why this would happen since I first reference a static method, then instantiates the class reference that function returnes and then call a function on the newly initilized class...
AbstractClass.ts
export abstract class AbstractClass {
abstract getModelName(): string;
public static get(id: string): Type<AbstractClass> {
switch (id) {
case "MyId1":
return MyId1ImplementationClass;
case "MyId2":
return MyId2ImplementationClass;
default:
return MyId1ImplementationClass;
}
}
}
MyId1ImplementationClass.ts
export class MyId1ImplementationClass extends AbstractClass {
getModelName(): string {
return "Id1!";
}
}
MyId2ImplementationClass.ts
export class MyId2ImplementationClass extends AbstractClass {
getModelName(): string {
return "Id2!";
}
}