From 433312c55aaece880c4ca040439948a28caa6da5 Mon Sep 17 00:00:00 2001 From: anov21 <42506016+anov21@users.noreply.github.com> Date: Tue, 22 Feb 2022 12:34:37 +0800 Subject: [PATCH] add the missing checkNullConditionnal code in the "GenObjApi" function when the field is scalar optional (#7114) --- src/idl_gen_ts.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/idl_gen_ts.cpp b/src/idl_gen_ts.cpp index f51155488..6ab336089 100644 --- a/src/idl_gen_ts.cpp +++ b/src/idl_gen_ts.cpp @@ -1079,6 +1079,9 @@ class TsGenerator : public BaseGenerator { if (has_create) { pack_func_create_call += field_offset_val; } else { + if (field.IsScalarOptional()) { + pack_func_create_call += " if (" + field_offset_val + " !== null)\n "; + } pack_func_create_call += " " + struct_name + ".add" + MakeCamel(field.name) + "(builder, " + field_offset_val + ");\n";