The wording of my question might be poor, but I'm trying to extend multiple classes in TypeScript and whenever I instantiate the object, I don't want any of the properties to be undefined. So in my various classes, I assign the variables values, but when I log it, they don't show up. In reading the Typescript docs, they mention using a mixin and that works if I want to access a variable, but all the variables are undefined, even though I defined them.
What I'm looking for is this...
const c = new C();
console.log(c)
Whenever I console log this is what I want to see
"propC1": "C1"
"propA1": "A1"
"propA2": "A2"
"propB1": "B1"
"propB2": "B2"
"myNumber": 1000
Instead I only see
"propC1": "C1"
Here is the code
function applyMixins(derivedCtor: any, baseCtors: any[]) {
baseCtors.forEach(baseCtor => {
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
if (name !== 'constructor') {
derivedCtor.prototype[name] = baseCtor.prototype[name];
}
});
});
}
class Z {
constructor(public myNumber = 1000){}
}
class A extends Z{
constructor(...){
super();
}
}
class B{
constructor(...){}
}
interface C extends A, B {}
class C implements A, B{
public propC1 = "C1";
}
applyMixins (C, [A, B]);