Skip to content

Commit bd5dc69

Browse files
committed
Initialize arrays to empty array in the constructor (if json['prop'] is not null)
1 parent 7f15b5e commit bd5dc69

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/Tool/Tool-typescript.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ end
175175
elseif f[:is_onetomany]
176176
elt_type = get_typescript_elt_type(f)
177177
str *= indent * "if (_json['$field_name'] != null) {\n"
178+
str *= indent * " " * "this.$field_name = [];\n"
178179
str *= indent * " " * "for (let e of _json['$field_name']) {\n"
179180
str *= indent * " " * "this.$field_name.push(new $elt_type(e));\n"
180181
str *= indent * " " * "}\n"
@@ -186,6 +187,7 @@ end
186187
elseif f[:is_vectorofenum]
187188
elt_type = get_typescript_elt_type(f)
188189
str *= indent * "if (_json['$field_name'] != null) {\n"
190+
str *= indent * " " * "this.$field_name = [];\n"
189191
str *= indent * " " * "for (let e of _json['$field_name']) {\n"
190192
str *= indent * " " * "this.$field_name.push(Number($elt_type[e]));\n"
191193
str *= indent * " " * "}\n"

0 commit comments

Comments
 (0)