My project involves utilizing multiple classes that represent entities from a database.
abstract class Entity {
static columns: Column[];
static showInNav: boolean;
static dependencies: string[];
// non-static fields
}
class Entity_A extends Entity {
//static properties redeclaration
//non-static properties
}
class Entity_B extends Entity {
//static properties redeclaration
//non-static properties
}
Each class extends the Entity class or one of its children.
During the initialization phase, I store these classes in an array [Entity_A, Entity_B, ...]
, iterate over them, and retrieve their properties to properly configure the application. These static properties serve as the configuration settings.
The challenge arises because TypeScript lacks a static contract, making it prone to mistakes and difficult to debug (which is not considered best practice).
One potential solution could be to convert static properties to methods and access them using new currentClass().property
.
However, I believe there must be a more efficient approach.
Any suggestions?
Edit (desired outcome): I aim to securely define "configuration" within classes (including typechecking and mandatory overrides) while easily accessing this information when provided with an array of classes.