I'm on a quest to dynamically create instances of various classes without the need to explicitly define each one. My ultimate goal is to implement the decorator pattern, but I've hit a roadblock in TypeScript due to compilation limitations.
Despite my efforts with Proxies, I haven't had much luck.
Below is a snippet of the usage I'm aiming for (though some crucial code is missing to enable me to achieve what I have in mind - this is the puzzle I'm currently working on).
class Person {
public name: string;
public age: number;
public identify() {
console.log(`${this.name} age ${this.age}`);
}
}
class Child {
public Mother: Person;
public Father: Person;
public logParents() {
console.log("Parents:");
this.Mother.identify();
this.Father.identify();
}
}
class Student {
public school: string;
public logSchool() {
console.log(this.school);
}
}
let Dad = new Person();
Dad.name = "Brad";
Dad.age = 32;
let Mom = new Person();
Mom = new Student(Mom);
Mom.name = "Janet";
Mom.age = 34;
Mom.school = "College of Night School Moms";
let Johnny = new Person();
Johnny = new Child(Johnny);
Johnny = new Student(Johnny);
Johnny.name = "Johnny";
Johnny.age = 12;
Johnny.Mother = Mom;
Johnny,Father = Dad;
Johnny.school = "School for kids who can't read good";