Saturday, December 1, 2018

Don't new up classes like interfaces in TypeScript.

Which is better?
let cat = new Cat();
cat.Name = "Frank";
cat.Lives = 9;
 
let cat:Cat = <Cat>{
   Name: "Frank",
   Lives: 9
};
Well, if you cast JSON to a class as you might an interface (as shown here) you will sidestep the constructor which isn't cool. I hate it that I cannot make a new class in TypeScript as I can in C# by just breaking into curly braces and assigning all properties upon a new up. I hate it that I have to assign all of the properties in a onesies and twosies manner. Yet, that is the way to go. Rats!

No comments:

Post a Comment