vojtechhabarta/typescript-generator

Default values for class constructors

Opened this issue · 0 comments

As a follow up of #1041:
I create a default constructor for the output. In my inherited children I have in the Java code the following base defintion:

private List<T> children = new ArrayList<>();

but somehow the assignment is not taken over for the class constructor. I only have

constructor(data: ChapterDto<T>) {
		this.children = data.children;
}

but would prefer to have the default settings from Java take over as well. Basically the code should look like

constructor(data: ChapterDto<T>) {
		this.children = data.children ?? [] as T[];
}

or more generally speaking: is there a way

  • to set the default Java values to the Typescript objects (e.g. int will be 0, boolean will be false, ...)?
  • to take over the definitions from Java into the class constructors?