I am encountering an issue with typescript typings in my current project. Specifically, I'm developing a small game engine that follows the entity-component-system model. My goal is to convert types of interfaces into an array of classes to define the necessary components for the system.
My ideal outcome would be:
export interface IMovable {
position: CompPosition;
velocity: CompVelocity;
}
export class MoveSystem extends System<IMovable> {
// This array should specify all component classes from IMovable.
protected requiredComponents = [ CompPosition, CompVelocity ];
/// ...
}
Alternatively, I aim to achieve:
export interface IMovable {
position: CompPosition;
velocity: CompVelocity;
}
export class MoveSystem extends System<IMovable> {
/* The properties of requiredComponents have the same name as in the interface,
but their types are different - instances in the interface and classes in
requiredComponents. */
protected requiredComponents = {
position: CompPosition,
velocity: CompVelocity
};
/// ...
}
Any suggestions or advice are greatly appreciated.