vojtechhabarta / typescript-generator

Generates TypeScript from Java - JSON declarations, REST service client
MIT License
1.14k stars 237 forks source link

Default values for class constructors #1042

Open leomayer opened 9 months ago

leomayer commented 9 months ago

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