This code is posing a problem to me:
var makeVariableOfClass = (sentClass: typeof Entity) => {
var newEntity = new sentClass();
}
interface EntityProps {
sentient: boolean;
}
class Entity {
private sentient: boolean;
constructor(props: EntityProps) {
this.sentient = props.sentient
}
}
class Person extends Entity {
constructor() {
super({sentient: true});
}
}
class Wall extends Entity {
constructor() {
super({sentient: false});
}
}
I'd like to be able to programmatically declare either a person or a wall (in this example), but the typing of Entity in makeVariableOfClass requires the EntityProps, even though I only want to send in a subset of things (Person and Wall). I understand that I could make sentClass be of type typeof Person | typeof Wall, but I'd like to be more scalable than that. Is there another way to get around this without typeof Person | typeof Wall | typeof ... ?
new sentClass()because it wants you to pass in props.