I’m struggling with TS constructors. Ill post this on stackoverflow, also.
Say you want to make the equivalent of these three constructors:
public Animal(){ this.name = “default”; this.noise =””; public Animal(string name){ this.name = name; this.noise = “”; } public Animal(string name, string noise){ this.name = name; this.noise = noise; } Do you do something like this in Typescript?
Constructor(name?:string, noise?:string){ if(name!= null) this.name =name; else this.name = ""; if(string != null) this.noise = noise; else this.noise = ""; } And so forth?
What about if you also have various primitives coming in say, you could declare an animal with an int or a string. Do you just use instanceof?
Thanks! Nathan