Hi I am new to TypeScript and I come from both a C# and JavaScript background. I am trying to create a way that allows me to create class models similar to what we can do in C#.
Here is what I have tried:
export class DonutChartModel {
dimension: number;
innerRadius: number;
backgroundClass: string;
backgroundOpacity: number;
}
I expected this to generate a JavaScript model that exposes the properties declared, but this generates only a function DonutChartModel
with no properties declared.
After looking at the docs I noticed that in order to expose the properties I have to add a constructor and initialize the properties from there. While this may work, it does not help situations where you may have 20 or more properties per model, as the initialization might look pretty clunky, in my opinion, and it also reduces readability a bit.
I am hoping there is a way to do something like this without passing constructor params:
var model = new DonutChartModel();
model.dimension = 5
model.innerRadius = 20
....
Is there any option in TypeScript to do this?