Greetings! As a newcomer to TypeScript with a background in both C# and JavaScript, I am on a quest to create class models resembling those found in C#.
Here's my attempt so far:
export class DonutChartModel {
dimension: number;
innerRadius: number;
backgroundClass: string;
backgroundOpacity: number;
}
I anticipated that this would produce a JavaScript model with the declared properties exposed. However, it only generates a function DonutChartModel
without any declared properties.
Upon consulting the documentation, I discovered that in order to expose the properties, I must include a constructor and initialize the properties within it. While this approach may be functional, it becomes cumbersome when dealing with numerous properties per model, impacting readability as well.
I am hopeful that there is an alternative method to achieve this without having to pass constructor parameters:
var model = new DonutChartModel();
model.dimension = 5
model.innerRadius = 20
....
Is there a way to accomplish this in TypeScript?