Skip to content

Commit 497e695

Browse files
committed
Allow numeric values for enums in the constructor
1 parent 4719f7d commit 497e695

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Tool/Tool-typescript.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,22 @@ end
182182
str *= indent * "}\n"
183183
elseif f[:is_enum]
184184
str *= indent * "if (_json['$field_name'] != null) {\n"
185-
str *= indent * " " * "this.$field_name = Number($(get_typescript_type_of_elt_type(f[:field_type]))[_json['$field_name']]);\n"
185+
str *= indent * " " * "if (isNaN(Number(_json['$field_name']))) {\n"
186+
str *= indent * " " * " " * "this.$field_name = Number($(get_typescript_type_of_elt_type(f[:field_type]))[_json['$field_name']]);\n"
187+
str *= indent * " " * "} else {\n"
188+
str *= indent * " " * " " * "this.$field_name = Number(_json['$field_name']);\n"
189+
str *= indent * " " * "}\n"
186190
str *= indent * "}\n"
187191
elseif f[:is_vectorofenum]
188192
elt_type = get_typescript_elt_type(f)
189193
str *= indent * "if (_json['$field_name'] != null) {\n"
190194
str *= indent * " " * "this.$field_name = [];\n"
191195
str *= indent * " " * "for (let e of _json['$field_name']) {\n"
192-
str *= indent * " " * "this.$field_name.push(Number($elt_type[e]));\n"
196+
str *= indent * " " * " " * "if (isNaN(Number(e))) {\n"
197+
str *= indent * " " * " " * " " * "this.$field_name.push(Number($elt_type[e]));\n"
198+
str *= indent * " " * " " * "} else {\n"
199+
str *= indent * " " * " " * " " * "this.$field_name.push(Number(e));\n"
200+
str *= indent * " " * " " * "}\n"
193201
str *= indent * " " * "}\n"
194202
str *= indent * "}\n"
195203
elseif get_typescript_type(f) == "Date"

0 commit comments

Comments
 (0)