I've encountered a dilemma with the code snippet below:
class Action {
public static DEPENDENCIES: (typeof Action)[] = [];
public static MIN_USES: number | null = null;
public static MAX_USES: number | null = null;
}
class SomeAction extends Action {
public static DEPENDENCIES = [SomeOtherAction];
public statuc MIN_USES = null;
public static MAX_USES = 1;
}
class SomeOtherAction extends Action {
public static DEPENDENCIES = [];
public static MIN_USES = 1;
public static MAX_USES = 1;
}
When trying to access a static property like this:
class Turn {
public can(A: typeof Action) {
console.log(A.MIN_USES);
}
}
turn.can(SomeOtherAction); // console.log(1);
Now, I aim to give SomeOtherAction a constructor with two parameters.
This modification triggers an error message:
Class static side 'typeof SomeOtherAction' incorrectly extends base class static side 'typeof Action'.
The root of the issue lies in the differing constructor signatures, which led me to replace (typeof Action)[]
with
(new(...args: any[]) => Action)[]
.
Nevertheless, by making this change, it seems that I lose the ability to access static properties:
Property 'MIN_USES' does not exist on type 'new (...args: any[]) => Action'.
Is there a way to reconcile accessing static properties and accommodating various constructor signatures?