From 142401f50a71d23f6088328235b34d00e536937a Mon Sep 17 00:00:00 2001
From: Kamil Rojewski <krojew@users.noreply.github.com>
Date: Thu, 14 Dec 2017 17:30:02 +0100
Subject: [PATCH] Fix for strictPropertyInitialization for TS (#4540)

* Eclipse ignore

* TypeScript support

* Prefixing enums

* Test results

* Merged JS and TS generators

* Fixed AppVeyor build problems

* Fixed more AppVeyor build problems

* Fixed more AppVeyor build problems

* Changed TS flag to options struct

* Storing options by value

* Removed unneeded const

* Re-export support for unions

* Uint support

* Casting bools to numbers for mutation

* TS shell tests

* Reverted generates js test file to original version

* Backing up js tests and properly generating test data

* Not importing flatbuffers for TS test generation

* Not overwriting generated js for tests

* AppVeyor test fixes

* Generating the most strict TS code possible

* Not returning null when creating vectors

* Not returning null from struct contructors

* Vector of unions for ts/js

* Sanity check for languages

* Indentation fix + output test files

* Vectors of unions for php

* Fixes to union vector handling + tests

* Fix for strictPropertyInitialization
---
 src/idl_gen_js.cpp                            |  50 +-
 tests/monster_test.bfbs                       | Bin 5520 -> 5400 bytes
 tests/monster_test_generated.ts               | 474 +++++++++---------
 .../namespace_test1_generated.ts              |  24 +-
 .../namespace_test2_generated.ts              |  48 +-
 tests/union_vector/union_vector_generated.ts  |  60 +--
 6 files changed, 331 insertions(+), 325 deletions(-)

diff --git a/src/idl_gen_js.cpp b/src/idl_gen_js.cpp
index c4359864..cf7ac2f9 100644
--- a/src/idl_gen_js.cpp
+++ b/src/idl_gen_js.cpp
@@ -361,12 +361,12 @@ static std::string GenType(const Type &type) {
 
 std::string GenGetter(const Type &type, const std::string &arguments) {
   switch (type.base_type) {
-    case BASE_TYPE_STRING: return "this.bb.__string" + arguments;
-    case BASE_TYPE_STRUCT: return "this.bb.__struct" + arguments;
-    case BASE_TYPE_UNION:  return "this.bb.__union" + arguments;
+    case BASE_TYPE_STRING: return GenBBAccess() + ".__string" + arguments;
+    case BASE_TYPE_STRUCT: return GenBBAccess() + ".__struct" + arguments;
+    case BASE_TYPE_UNION:  return GenBBAccess() + ".__union" + arguments;
     case BASE_TYPE_VECTOR: return GenGetter(type.VectorType(), arguments);
     default: {
-      auto getter = "this.bb.read" + MakeCamel(GenType(type)) + arguments;
+      auto getter = GenBBAccess() + ".read" + MakeCamel(GenType(type)) + arguments;
       if (type.base_type == BASE_TYPE_BOOL) {
         getter = "!!" + getter;
       }
@@ -379,6 +379,10 @@ std::string GenGetter(const Type &type, const std::string &arguments) {
   }
 }
 
+std::string GenBBAccess() {
+  return lang_.language == IDLOptions::kTs ? "this.bb!" : "this.bb";
+}
+
 std::string GenDefaultValue(const Value &value, const std::string &context) {
   if (value.type.enum_def) {
     if (auto val = value.type.enum_def->ReverseLookup(
@@ -570,7 +574,7 @@ void GenStruct(const Parser &parser, StructDef &struct_def,
     code += "  /**\n";
     code += "   * @type {flatbuffers.ByteBuffer}\n";
     code += "   */\n";
-    code += "  bb: flatbuffers.ByteBuffer;\n";
+    code += "  bb: flatbuffers.ByteBuffer|null = null;\n";
     code += "\n";
     code += "  /**\n";
     code += "   * @type {number}\n";
@@ -666,8 +670,9 @@ void GenStruct(const Parser &parser, StructDef &struct_def,
        it != struct_def.fields.vec.end(); ++it) {
     auto &field = **it;
     if (field.deprecated) continue;
-    auto offset_prefix = "  var offset = this.bb.__offset(this.bb_pos, " +
-      NumToString(field.value.offset) + ");\n  return offset ? ";
+    auto offset_prefix = "  var offset = " + GenBBAccess() +
+      ".__offset(this.bb_pos, " + NumToString(field.value.offset) +
+      ");\n  return offset ? ";
 
     // Emit a scalar field
     if (IsScalar(field.value.type.base_type) ||
@@ -711,7 +716,7 @@ void GenStruct(const Parser &parser, StructDef &struct_def,
           index += ", optionalEncoding";
         }
         code += offset_prefix + GenGetter(field.value.type,
-          "(" + index + ")") + " : " + GenDefaultValue(field.value, "this.bb");
+          "(" + index + ")") + " : " + GenDefaultValue(field.value, GenBBAccess());
         code += ";\n";
       }
     }
@@ -735,13 +740,13 @@ void GenStruct(const Parser &parser, StructDef &struct_def,
           if (struct_def.fixed) {
             code += "  return (obj || new " + type;
             code += ").__init(this.bb_pos";
-            code += MaybeAdd(field.value.offset) + ", this.bb);\n";
+            code += MaybeAdd(field.value.offset) + ", " + GenBBAccess() + ");\n";
           } else {
             code += offset_prefix + "(obj || new " + type + ").__init(";
             code += field.value.type.struct_def->fixed
               ? "this.bb_pos + offset"
-              : "this.bb.__indirect(this.bb_pos + offset)";
-            code += ", this.bb) : null;\n";
+              : GenBBAccess() + ".__indirect(this.bb_pos + offset)";
+            code += ", " + GenBBAccess() + ") : null;\n";
           }
 
           if (lang_.language == IDLOptions::kTs) {
@@ -755,7 +760,7 @@ void GenStruct(const Parser &parser, StructDef &struct_def,
           auto vectortype = field.value.type.VectorType();
           auto vectortypename = GenTypeName(vectortype, false);
           auto inline_size = InlineSize(vectortype);
-          auto index = "this.bb.__vector(this.bb_pos + offset) + index" +
+          auto index = GenBBAccess() + ".__vector(this.bb_pos + offset) + index" +
                        MaybeScale(inline_size);
           std::string args = "@param {number} index\n";
           std::string ret_type;
@@ -818,8 +823,8 @@ void GenStruct(const Parser &parser, StructDef &struct_def,
             code += ").__init(";
             code += vectortype.struct_def->fixed
               ? index
-              : "this.bb.__indirect(" + index + ")";
-            code += ", this.bb)";
+              : GenBBAccess() + ".__indirect(" + index + ")";
+            code += ", " + GenBBAccess() + ")";
           } else {
             if (is_union) {
               index = "obj, " + index;
@@ -833,7 +838,7 @@ void GenStruct(const Parser &parser, StructDef &struct_def,
             code += "false";
           } else if (field.value.type.element == BASE_TYPE_LONG ||
               field.value.type.element == BASE_TYPE_ULONG) {
-            code += "this.bb.createLong(0, 0)";
+            code += GenBBAccess() + ".createLong(0, 0)";
           } else if (IsScalar(field.value.type.element)) {
             if (field.value.type.enum_def) {
               code += "/** @type {" +
@@ -899,15 +904,15 @@ void GenStruct(const Parser &parser, StructDef &struct_def,
                 " = function(value) {\n";
       }
 
-      code += "  var offset = this.bb.__offset(this.bb_pos, " +
+      code += "  var offset = " + GenBBAccess() + ".__offset(this.bb_pos, " +
               NumToString(field.value.offset) + ");\n\n";
       code += "  if (offset === 0) {\n";
       code += "    return false;\n";
       code += "  }\n\n";
 
       // special case for bools, which are treated as uint8
-      code += "  this.bb.write" + MakeCamel(GenType(field.value.type)) +
-              "(this.bb_pos + offset, ";
+      code += "  " + GenBBAccess() + ".write" +
+        MakeCamel(GenType(field.value.type)) + "(this.bb_pos + offset, ";
       if (field.value.type.base_type == BASE_TYPE_BOOL &&
           lang_.language == IDLOptions::kTs) {
           code += "+";
@@ -936,7 +941,7 @@ void GenStruct(const Parser &parser, StructDef &struct_def,
         code += "Length = function() {\n" + offset_prefix;
       }
 
-      code += "this.bb.__vector_len(this.bb_pos + offset) : 0;\n};\n\n";
+      code += GenBBAccess() + ".__vector_len(this.bb_pos + offset) : 0;\n};\n\n";
 
       if(parser_.opts.use_goog_js_export_format) {
         exports += "goog.exportProperty(" + object_name + ".prototype, '" +
@@ -958,9 +963,10 @@ void GenStruct(const Parser &parser, StructDef &struct_def,
           code += "Array = function() {\n" + offset_prefix;
         }
 
-        code += "new " + GenType(vectorType) + "Array(this.bb.bytes().buffer, "
-          "this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), "
-          "this.bb.__vector_len(this.bb_pos + offset)) : null;\n};\n\n";
+        code += "new " + GenType(vectorType) + "Array(" + GenBBAccess() +
+          ".bytes().buffer, " + GenBBAccess() + ".bytes().byteOffset + " +
+          GenBBAccess() + ".__vector(this.bb_pos + offset), " +
+          GenBBAccess() + ".__vector_len(this.bb_pos + offset)) : null;\n};\n\n";
 
         if(parser_.opts.use_goog_js_export_format) {
           exports += "goog.exportProperty(" + object_name + ".prototype, '" +
diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs
index 2e247eb3af964b0f0aa98041a26d12cb0ebb965b..843e308c5204d9c36bad66ae49ac2d37041b4cce 100644
GIT binary patch
literal 5400
zcmai&e`uE16~}L4j4@438m-Mz*F9!ML_*N$q(~_-Q)@+|ROgBe;+y1o%`5NwJmLM3
z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ygy~pG2
zV@!FTdj9M^SexwoR|<o8qOC4afjtC$)-RTnrmcWX+Fr)~@%DblZ#M8@D+T`rPx#0H

diff --git a/tests/monster_test_generated.ts b/tests/monster_test_generated.ts
index fa4e9630..98fc4c5e 100644
--- a/tests/monster_test_generated.ts
+++ b/tests/monster_test_generated.ts
@@ -29,7 +29,7 @@ export class InParentNamespace {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -81,7 +81,7 @@ export class Monster {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -133,7 +133,7 @@ export class Test {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -154,7 +154,7 @@ __init(i:number, bb:flatbuffers.ByteBuffer):Test {
  * @returns {number}
  */
 a():number {
-  return this.bb.readInt16(this.bb_pos);
+  return this.bb!.readInt16(this.bb_pos);
 };
 
 /**
@@ -162,13 +162,13 @@ a():number {
  * @returns {boolean}
  */
 mutate_a(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 0);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt16(this.bb_pos + offset, value);
+  this.bb!.writeInt16(this.bb_pos + offset, value);
   return true;
 };
 
@@ -176,7 +176,7 @@ mutate_a(value:number):boolean {
  * @returns {number}
  */
 b():number {
-  return this.bb.readInt8(this.bb_pos + 2);
+  return this.bb!.readInt8(this.bb_pos + 2);
 };
 
 /**
@@ -184,13 +184,13 @@ b():number {
  * @returns {boolean}
  */
 mutate_b(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 2);
+  var offset = this.bb!.__offset(this.bb_pos, 2);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt8(this.bb_pos + offset, value);
+  this.bb!.writeInt8(this.bb_pos + offset, value);
   return true;
 };
 
@@ -218,7 +218,7 @@ export class TestSimpleTableWithEnum {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -248,8 +248,8 @@ static getRootAsTestSimpleTableWithEnum(bb:flatbuffers.ByteBuffer, obj?:TestSimp
  * @returns {MyGame.Example.Color}
  */
 color():MyGame.Example.Color {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? /** @type {MyGame.Example.Color} */ (this.bb.readInt8(this.bb_pos + offset)) : MyGame.Example.Color.Green;
+  var offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? /** @type {MyGame.Example.Color} */ (this.bb!.readInt8(this.bb_pos + offset)) : MyGame.Example.Color.Green;
 };
 
 /**
@@ -257,13 +257,13 @@ color():MyGame.Example.Color {
  * @returns {boolean}
  */
 mutate_color(value:MyGame.Example.Color):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 4);
+  var offset = this.bb!.__offset(this.bb_pos, 4);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt8(this.bb_pos + offset, value);
+  this.bb!.writeInt8(this.bb_pos + offset, value);
   return true;
 };
 
@@ -301,7 +301,7 @@ export class Vec3 {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -322,7 +322,7 @@ __init(i:number, bb:flatbuffers.ByteBuffer):Vec3 {
  * @returns {number}
  */
 x():number {
-  return this.bb.readFloat32(this.bb_pos);
+  return this.bb!.readFloat32(this.bb_pos);
 };
 
 /**
@@ -330,13 +330,13 @@ x():number {
  * @returns {boolean}
  */
 mutate_x(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 0);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeFloat32(this.bb_pos + offset, value);
+  this.bb!.writeFloat32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -344,7 +344,7 @@ mutate_x(value:number):boolean {
  * @returns {number}
  */
 y():number {
-  return this.bb.readFloat32(this.bb_pos + 4);
+  return this.bb!.readFloat32(this.bb_pos + 4);
 };
 
 /**
@@ -352,13 +352,13 @@ y():number {
  * @returns {boolean}
  */
 mutate_y(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 4);
+  var offset = this.bb!.__offset(this.bb_pos, 4);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeFloat32(this.bb_pos + offset, value);
+  this.bb!.writeFloat32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -366,7 +366,7 @@ mutate_y(value:number):boolean {
  * @returns {number}
  */
 z():number {
-  return this.bb.readFloat32(this.bb_pos + 8);
+  return this.bb!.readFloat32(this.bb_pos + 8);
 };
 
 /**
@@ -374,13 +374,13 @@ z():number {
  * @returns {boolean}
  */
 mutate_z(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 8);
+  var offset = this.bb!.__offset(this.bb_pos, 8);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeFloat32(this.bb_pos + offset, value);
+  this.bb!.writeFloat32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -388,7 +388,7 @@ mutate_z(value:number):boolean {
  * @returns {number}
  */
 test1():number {
-  return this.bb.readFloat64(this.bb_pos + 16);
+  return this.bb!.readFloat64(this.bb_pos + 16);
 };
 
 /**
@@ -396,13 +396,13 @@ test1():number {
  * @returns {boolean}
  */
 mutate_test1(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 16);
+  var offset = this.bb!.__offset(this.bb_pos, 16);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeFloat64(this.bb_pos + offset, value);
+  this.bb!.writeFloat64(this.bb_pos + offset, value);
   return true;
 };
 
@@ -410,7 +410,7 @@ mutate_test1(value:number):boolean {
  * @returns {MyGame.Example.Color}
  */
 test2():MyGame.Example.Color {
-  return /** @type {MyGame.Example.Color} */ (this.bb.readInt8(this.bb_pos + 24));
+  return /** @type {MyGame.Example.Color} */ (this.bb!.readInt8(this.bb_pos + 24));
 };
 
 /**
@@ -418,13 +418,13 @@ test2():MyGame.Example.Color {
  * @returns {boolean}
  */
 mutate_test2(value:MyGame.Example.Color):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 24);
+  var offset = this.bb!.__offset(this.bb_pos, 24);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt8(this.bb_pos + offset, value);
+  this.bb!.writeInt8(this.bb_pos + offset, value);
   return true;
 };
 
@@ -433,7 +433,7 @@ mutate_test2(value:MyGame.Example.Color):boolean {
  * @returns {MyGame.Example.Test|null}
  */
 test3(obj?:MyGame.Example.Test):MyGame.Example.Test|null {
-  return (obj || new MyGame.Example.Test).__init(this.bb_pos + 26, this.bb);
+  return (obj || new MyGame.Example.Test).__init(this.bb_pos + 26, this.bb!);
 };
 
 /**
@@ -474,7 +474,7 @@ export class Ability {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -495,7 +495,7 @@ __init(i:number, bb:flatbuffers.ByteBuffer):Ability {
  * @returns {number}
  */
 id():number {
-  return this.bb.readUint32(this.bb_pos);
+  return this.bb!.readUint32(this.bb_pos);
 };
 
 /**
@@ -503,13 +503,13 @@ id():number {
  * @returns {boolean}
  */
 mutate_id(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 0);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint32(this.bb_pos + offset, value);
+  this.bb!.writeUint32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -517,7 +517,7 @@ mutate_id(value:number):boolean {
  * @returns {number}
  */
 distance():number {
-  return this.bb.readUint32(this.bb_pos + 4);
+  return this.bb!.readUint32(this.bb_pos + 4);
 };
 
 /**
@@ -525,13 +525,13 @@ distance():number {
  * @returns {boolean}
  */
 mutate_distance(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 4);
+  var offset = this.bb!.__offset(this.bb_pos, 4);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint32(this.bb_pos + offset, value);
+  this.bb!.writeUint32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -558,7 +558,7 @@ export class Stat {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -591,16 +591,16 @@ static getRootAsStat(bb:flatbuffers.ByteBuffer, obj?:Stat):Stat {
 id():string|null
 id(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
 id(optionalEncoding?:any):string|Uint8Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
 };
 
 /**
  * @returns {flatbuffers.Long}
  */
 val():flatbuffers.Long {
-  var offset = this.bb.__offset(this.bb_pos, 6);
-  return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 6);
+  return offset ? this.bb!.readInt64(this.bb_pos + offset) : this.bb!.createLong(0, 0);
 };
 
 /**
@@ -608,13 +608,13 @@ val():flatbuffers.Long {
  * @returns {boolean}
  */
 mutate_val(value:flatbuffers.Long):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 6);
+  var offset = this.bb!.__offset(this.bb_pos, 6);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt64(this.bb_pos + offset, value);
+  this.bb!.writeInt64(this.bb_pos + offset, value);
   return true;
 };
 
@@ -622,8 +622,8 @@ mutate_val(value:flatbuffers.Long):boolean {
  * @returns {number}
  */
 count():number {
-  var offset = this.bb.__offset(this.bb_pos, 8);
-  return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 8);
+  return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -631,13 +631,13 @@ count():number {
  * @returns {boolean}
  */
 mutate_count(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 8);
+  var offset = this.bb!.__offset(this.bb_pos, 8);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint16(this.bb_pos + offset, value);
+  this.bb!.writeUint16(this.bb_pos + offset, value);
   return true;
 };
 
@@ -693,7 +693,7 @@ export class Monster {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -732,16 +732,16 @@ static bufferHasIdentifier(bb:flatbuffers.ByteBuffer):boolean {
  * @returns {MyGame.Example.Vec3|null}
  */
 pos(obj?:MyGame.Example.Vec3):MyGame.Example.Vec3|null {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? (obj || new MyGame.Example.Vec3).__init(this.bb_pos + offset, this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? (obj || new MyGame.Example.Vec3).__init(this.bb_pos + offset, this.bb!) : null;
 };
 
 /**
  * @returns {number}
  */
 mana():number {
-  var offset = this.bb.__offset(this.bb_pos, 6);
-  return offset ? this.bb.readInt16(this.bb_pos + offset) : 150;
+  var offset = this.bb!.__offset(this.bb_pos, 6);
+  return offset ? this.bb!.readInt16(this.bb_pos + offset) : 150;
 };
 
 /**
@@ -749,13 +749,13 @@ mana():number {
  * @returns {boolean}
  */
 mutate_mana(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 6);
+  var offset = this.bb!.__offset(this.bb_pos, 6);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt16(this.bb_pos + offset, value);
+  this.bb!.writeInt16(this.bb_pos + offset, value);
   return true;
 };
 
@@ -763,8 +763,8 @@ mutate_mana(value:number):boolean {
  * @returns {number}
  */
 hp():number {
-  var offset = this.bb.__offset(this.bb_pos, 8);
-  return offset ? this.bb.readInt16(this.bb_pos + offset) : 100;
+  var offset = this.bb!.__offset(this.bb_pos, 8);
+  return offset ? this.bb!.readInt16(this.bb_pos + offset) : 100;
 };
 
 /**
@@ -772,13 +772,13 @@ hp():number {
  * @returns {boolean}
  */
 mutate_hp(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 8);
+  var offset = this.bb!.__offset(this.bb_pos, 8);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt16(this.bb_pos + offset, value);
+  this.bb!.writeInt16(this.bb_pos + offset, value);
   return true;
 };
 
@@ -789,8 +789,8 @@ mutate_hp(value:number):boolean {
 name():string|null
 name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
 name(optionalEncoding?:any):string|Uint8Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 10);
-  return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 10);
+  return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
 };
 
 /**
@@ -798,32 +798,32 @@ name(optionalEncoding?:any):string|Uint8Array|null {
  * @returns {number}
  */
 inventory(index: number):number|null {
-  var offset = this.bb.__offset(this.bb_pos, 14);
-  return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 14);
+  return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0;
 };
 
 /**
  * @returns {number}
  */
 inventoryLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 14);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 14);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
  * @returns {Uint8Array}
  */
 inventoryArray():Uint8Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 14);
-  return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 14);
+  return offset ? new Uint8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
 };
 
 /**
  * @returns {MyGame.Example.Color}
  */
 color():MyGame.Example.Color {
-  var offset = this.bb.__offset(this.bb_pos, 16);
-  return offset ? /** @type {MyGame.Example.Color} */ (this.bb.readInt8(this.bb_pos + offset)) : MyGame.Example.Color.Blue;
+  var offset = this.bb!.__offset(this.bb_pos, 16);
+  return offset ? /** @type {MyGame.Example.Color} */ (this.bb!.readInt8(this.bb_pos + offset)) : MyGame.Example.Color.Blue;
 };
 
 /**
@@ -831,13 +831,13 @@ color():MyGame.Example.Color {
  * @returns {boolean}
  */
 mutate_color(value:MyGame.Example.Color):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 16);
+  var offset = this.bb!.__offset(this.bb_pos, 16);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt8(this.bb_pos + offset, value);
+  this.bb!.writeInt8(this.bb_pos + offset, value);
   return true;
 };
 
@@ -845,8 +845,8 @@ mutate_color(value:MyGame.Example.Color):boolean {
  * @returns {MyGame.Example.Any}
  */
 testType():MyGame.Example.Any {
-  var offset = this.bb.__offset(this.bb_pos, 18);
-  return offset ? /** @type {MyGame.Example.Any} */ (this.bb.readUint8(this.bb_pos + offset)) : MyGame.Example.Any.NONE;
+  var offset = this.bb!.__offset(this.bb_pos, 18);
+  return offset ? /** @type {MyGame.Example.Any} */ (this.bb!.readUint8(this.bb_pos + offset)) : MyGame.Example.Any.NONE;
 };
 
 /**
@@ -854,13 +854,13 @@ testType():MyGame.Example.Any {
  * @returns {boolean}
  */
 mutate_test_type(value:MyGame.Example.Any):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 18);
+  var offset = this.bb!.__offset(this.bb_pos, 18);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint8(this.bb_pos + offset, value);
+  this.bb!.writeUint8(this.bb_pos + offset, value);
   return true;
 };
 
@@ -869,8 +869,8 @@ mutate_test_type(value:MyGame.Example.Any):boolean {
  * @returns {?flatbuffers.Table}
  */
 test<T extends flatbuffers.Table>(obj:T):T|null {
-  var offset = this.bb.__offset(this.bb_pos, 20);
-  return offset ? this.bb.__union(obj, this.bb_pos + offset) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 20);
+  return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null;
 };
 
 /**
@@ -879,16 +879,16 @@ test<T extends flatbuffers.Table>(obj:T):T|null {
  * @returns {MyGame.Example.Test}
  */
 test4(index: number, obj?:MyGame.Example.Test):MyGame.Example.Test|null {
-  var offset = this.bb.__offset(this.bb_pos, 22);
-  return offset ? (obj || new MyGame.Example.Test).__init(this.bb.__vector(this.bb_pos + offset) + index * 4, this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 22);
+  return offset ? (obj || new MyGame.Example.Test).__init(this.bb!.__vector(this.bb_pos + offset) + index * 4, this.bb!) : null;
 };
 
 /**
  * @returns {number}
  */
 test4Length():number {
-  var offset = this.bb.__offset(this.bb_pos, 22);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 22);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -899,16 +899,16 @@ test4Length():number {
 testarrayofstring(index: number):string
 testarrayofstring(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array
 testarrayofstring(index: number,optionalEncoding?:any):string|Uint8Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 24);
-  return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 24);
+  return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
 };
 
 /**
  * @returns {number}
  */
 testarrayofstringLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 24);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 24);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -920,16 +920,16 @@ testarrayofstringLength():number {
  * @returns {MyGame.Example.Monster}
  */
 testarrayoftables(index: number, obj?:MyGame.Example.Monster):MyGame.Example.Monster|null {
-  var offset = this.bb.__offset(this.bb_pos, 26);
-  return offset ? (obj || new MyGame.Example.Monster).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 26);
+  return offset ? (obj || new MyGame.Example.Monster).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
 };
 
 /**
  * @returns {number}
  */
 testarrayoftablesLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 26);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 26);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -937,8 +937,8 @@ testarrayoftablesLength():number {
  * @returns {MyGame.Example.Monster|null}
  */
 enemy(obj?:MyGame.Example.Monster):MyGame.Example.Monster|null {
-  var offset = this.bb.__offset(this.bb_pos, 28);
-  return offset ? (obj || new MyGame.Example.Monster).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 28);
+  return offset ? (obj || new MyGame.Example.Monster).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
 };
 
 /**
@@ -946,24 +946,24 @@ enemy(obj?:MyGame.Example.Monster):MyGame.Example.Monster|null {
  * @returns {number}
  */
 testnestedflatbuffer(index: number):number|null {
-  var offset = this.bb.__offset(this.bb_pos, 30);
-  return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 30);
+  return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0;
 };
 
 /**
  * @returns {number}
  */
 testnestedflatbufferLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 30);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 30);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
  * @returns {Uint8Array}
  */
 testnestedflatbufferArray():Uint8Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 30);
-  return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 30);
+  return offset ? new Uint8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
 };
 
 /**
@@ -971,16 +971,16 @@ testnestedflatbufferArray():Uint8Array|null {
  * @returns {MyGame.Example.Stat|null}
  */
 testempty(obj?:MyGame.Example.Stat):MyGame.Example.Stat|null {
-  var offset = this.bb.__offset(this.bb_pos, 32);
-  return offset ? (obj || new MyGame.Example.Stat).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 32);
+  return offset ? (obj || new MyGame.Example.Stat).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
 };
 
 /**
  * @returns {boolean}
  */
 testbool():boolean {
-  var offset = this.bb.__offset(this.bb_pos, 34);
-  return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false;
+  var offset = this.bb!.__offset(this.bb_pos, 34);
+  return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
 };
 
 /**
@@ -988,13 +988,13 @@ testbool():boolean {
  * @returns {boolean}
  */
 mutate_testbool(value:boolean):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 34);
+  var offset = this.bb!.__offset(this.bb_pos, 34);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt8(this.bb_pos + offset, +value);
+  this.bb!.writeInt8(this.bb_pos + offset, +value);
   return true;
 };
 
@@ -1002,8 +1002,8 @@ mutate_testbool(value:boolean):boolean {
  * @returns {number}
  */
 testhashs32Fnv1():number {
-  var offset = this.bb.__offset(this.bb_pos, 36);
-  return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 36);
+  return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -1011,13 +1011,13 @@ testhashs32Fnv1():number {
  * @returns {boolean}
  */
 mutate_testhashs32_fnv1(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 36);
+  var offset = this.bb!.__offset(this.bb_pos, 36);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt32(this.bb_pos + offset, value);
+  this.bb!.writeInt32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1025,8 +1025,8 @@ mutate_testhashs32_fnv1(value:number):boolean {
  * @returns {number}
  */
 testhashu32Fnv1():number {
-  var offset = this.bb.__offset(this.bb_pos, 38);
-  return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 38);
+  return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -1034,13 +1034,13 @@ testhashu32Fnv1():number {
  * @returns {boolean}
  */
 mutate_testhashu32_fnv1(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 38);
+  var offset = this.bb!.__offset(this.bb_pos, 38);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint32(this.bb_pos + offset, value);
+  this.bb!.writeUint32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1048,8 +1048,8 @@ mutate_testhashu32_fnv1(value:number):boolean {
  * @returns {flatbuffers.Long}
  */
 testhashs64Fnv1():flatbuffers.Long {
-  var offset = this.bb.__offset(this.bb_pos, 40);
-  return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 40);
+  return offset ? this.bb!.readInt64(this.bb_pos + offset) : this.bb!.createLong(0, 0);
 };
 
 /**
@@ -1057,13 +1057,13 @@ testhashs64Fnv1():flatbuffers.Long {
  * @returns {boolean}
  */
 mutate_testhashs64_fnv1(value:flatbuffers.Long):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 40);
+  var offset = this.bb!.__offset(this.bb_pos, 40);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt64(this.bb_pos + offset, value);
+  this.bb!.writeInt64(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1071,8 +1071,8 @@ mutate_testhashs64_fnv1(value:flatbuffers.Long):boolean {
  * @returns {flatbuffers.Long}
  */
 testhashu64Fnv1():flatbuffers.Long {
-  var offset = this.bb.__offset(this.bb_pos, 42);
-  return offset ? this.bb.readUint64(this.bb_pos + offset) : this.bb.createLong(0, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 42);
+  return offset ? this.bb!.readUint64(this.bb_pos + offset) : this.bb!.createLong(0, 0);
 };
 
 /**
@@ -1080,13 +1080,13 @@ testhashu64Fnv1():flatbuffers.Long {
  * @returns {boolean}
  */
 mutate_testhashu64_fnv1(value:flatbuffers.Long):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 42);
+  var offset = this.bb!.__offset(this.bb_pos, 42);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint64(this.bb_pos + offset, value);
+  this.bb!.writeUint64(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1094,8 +1094,8 @@ mutate_testhashu64_fnv1(value:flatbuffers.Long):boolean {
  * @returns {number}
  */
 testhashs32Fnv1a():number {
-  var offset = this.bb.__offset(this.bb_pos, 44);
-  return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 44);
+  return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -1103,13 +1103,13 @@ testhashs32Fnv1a():number {
  * @returns {boolean}
  */
 mutate_testhashs32_fnv1a(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 44);
+  var offset = this.bb!.__offset(this.bb_pos, 44);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt32(this.bb_pos + offset, value);
+  this.bb!.writeInt32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1117,8 +1117,8 @@ mutate_testhashs32_fnv1a(value:number):boolean {
  * @returns {number}
  */
 testhashu32Fnv1a():number {
-  var offset = this.bb.__offset(this.bb_pos, 46);
-  return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 46);
+  return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -1126,13 +1126,13 @@ testhashu32Fnv1a():number {
  * @returns {boolean}
  */
 mutate_testhashu32_fnv1a(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 46);
+  var offset = this.bb!.__offset(this.bb_pos, 46);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint32(this.bb_pos + offset, value);
+  this.bb!.writeUint32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1140,8 +1140,8 @@ mutate_testhashu32_fnv1a(value:number):boolean {
  * @returns {flatbuffers.Long}
  */
 testhashs64Fnv1a():flatbuffers.Long {
-  var offset = this.bb.__offset(this.bb_pos, 48);
-  return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 48);
+  return offset ? this.bb!.readInt64(this.bb_pos + offset) : this.bb!.createLong(0, 0);
 };
 
 /**
@@ -1149,13 +1149,13 @@ testhashs64Fnv1a():flatbuffers.Long {
  * @returns {boolean}
  */
 mutate_testhashs64_fnv1a(value:flatbuffers.Long):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 48);
+  var offset = this.bb!.__offset(this.bb_pos, 48);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt64(this.bb_pos + offset, value);
+  this.bb!.writeInt64(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1163,8 +1163,8 @@ mutate_testhashs64_fnv1a(value:flatbuffers.Long):boolean {
  * @returns {flatbuffers.Long}
  */
 testhashu64Fnv1a():flatbuffers.Long {
-  var offset = this.bb.__offset(this.bb_pos, 50);
-  return offset ? this.bb.readUint64(this.bb_pos + offset) : this.bb.createLong(0, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 50);
+  return offset ? this.bb!.readUint64(this.bb_pos + offset) : this.bb!.createLong(0, 0);
 };
 
 /**
@@ -1172,13 +1172,13 @@ testhashu64Fnv1a():flatbuffers.Long {
  * @returns {boolean}
  */
 mutate_testhashu64_fnv1a(value:flatbuffers.Long):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 50);
+  var offset = this.bb!.__offset(this.bb_pos, 50);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint64(this.bb_pos + offset, value);
+  this.bb!.writeUint64(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1187,32 +1187,32 @@ mutate_testhashu64_fnv1a(value:flatbuffers.Long):boolean {
  * @returns {boolean}
  */
 testarrayofbools(index: number):boolean|null {
-  var offset = this.bb.__offset(this.bb_pos, 52);
-  return offset ? !!this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index) : false;
+  var offset = this.bb!.__offset(this.bb_pos, 52);
+  return offset ? !!this.bb!.readInt8(this.bb!.__vector(this.bb_pos + offset) + index) : false;
 };
 
 /**
  * @returns {number}
  */
 testarrayofboolsLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 52);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 52);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
  * @returns {Int8Array}
  */
 testarrayofboolsArray():Int8Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 52);
-  return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 52);
+  return offset ? new Int8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
 };
 
 /**
  * @returns {number}
  */
 testf():number {
-  var offset = this.bb.__offset(this.bb_pos, 54);
-  return offset ? this.bb.readFloat32(this.bb_pos + offset) : 3.14159;
+  var offset = this.bb!.__offset(this.bb_pos, 54);
+  return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 3.14159;
 };
 
 /**
@@ -1220,13 +1220,13 @@ testf():number {
  * @returns {boolean}
  */
 mutate_testf(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 54);
+  var offset = this.bb!.__offset(this.bb_pos, 54);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeFloat32(this.bb_pos + offset, value);
+  this.bb!.writeFloat32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1234,8 +1234,8 @@ mutate_testf(value:number):boolean {
  * @returns {number}
  */
 testf2():number {
-  var offset = this.bb.__offset(this.bb_pos, 56);
-  return offset ? this.bb.readFloat32(this.bb_pos + offset) : 3.0;
+  var offset = this.bb!.__offset(this.bb_pos, 56);
+  return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 3.0;
 };
 
 /**
@@ -1243,13 +1243,13 @@ testf2():number {
  * @returns {boolean}
  */
 mutate_testf2(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 56);
+  var offset = this.bb!.__offset(this.bb_pos, 56);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeFloat32(this.bb_pos + offset, value);
+  this.bb!.writeFloat32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1257,8 +1257,8 @@ mutate_testf2(value:number):boolean {
  * @returns {number}
  */
 testf3():number {
-  var offset = this.bb.__offset(this.bb_pos, 58);
-  return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0;
+  var offset = this.bb!.__offset(this.bb_pos, 58);
+  return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0;
 };
 
 /**
@@ -1266,13 +1266,13 @@ testf3():number {
  * @returns {boolean}
  */
 mutate_testf3(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 58);
+  var offset = this.bb!.__offset(this.bb_pos, 58);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeFloat32(this.bb_pos + offset, value);
+  this.bb!.writeFloat32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1284,16 +1284,16 @@ mutate_testf3(value:number):boolean {
 testarrayofstring2(index: number):string
 testarrayofstring2(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array
 testarrayofstring2(index: number,optionalEncoding?:any):string|Uint8Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 60);
-  return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 60);
+  return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
 };
 
 /**
  * @returns {number}
  */
 testarrayofstring2Length():number {
-  var offset = this.bb.__offset(this.bb_pos, 60);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 60);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -1302,16 +1302,16 @@ testarrayofstring2Length():number {
  * @returns {MyGame.Example.Ability}
  */
 testarrayofsortedstruct(index: number, obj?:MyGame.Example.Ability):MyGame.Example.Ability|null {
-  var offset = this.bb.__offset(this.bb_pos, 62);
-  return offset ? (obj || new MyGame.Example.Ability).__init(this.bb.__vector(this.bb_pos + offset) + index * 8, this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 62);
+  return offset ? (obj || new MyGame.Example.Ability).__init(this.bb!.__vector(this.bb_pos + offset) + index * 8, this.bb!) : null;
 };
 
 /**
  * @returns {number}
  */
 testarrayofsortedstructLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 62);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 62);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -1319,24 +1319,24 @@ testarrayofsortedstructLength():number {
  * @returns {number}
  */
 flex(index: number):number|null {
-  var offset = this.bb.__offset(this.bb_pos, 64);
-  return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 64);
+  return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0;
 };
 
 /**
  * @returns {number}
  */
 flexLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 64);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 64);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
  * @returns {Uint8Array}
  */
 flexArray():Uint8Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 64);
-  return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 64);
+  return offset ? new Uint8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
 };
 
 /**
@@ -1345,16 +1345,16 @@ flexArray():Uint8Array|null {
  * @returns {MyGame.Example.Test}
  */
 test5(index: number, obj?:MyGame.Example.Test):MyGame.Example.Test|null {
-  var offset = this.bb.__offset(this.bb_pos, 66);
-  return offset ? (obj || new MyGame.Example.Test).__init(this.bb.__vector(this.bb_pos + offset) + index * 4, this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 66);
+  return offset ? (obj || new MyGame.Example.Test).__init(this.bb!.__vector(this.bb_pos + offset) + index * 4, this.bb!) : null;
 };
 
 /**
  * @returns {number}
  */
 test5Length():number {
-  var offset = this.bb.__offset(this.bb_pos, 66);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 66);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -1362,16 +1362,16 @@ test5Length():number {
  * @returns {flatbuffers.Long}
  */
 vectorOfLongs(index: number):flatbuffers.Long|null {
-  var offset = this.bb.__offset(this.bb_pos, 68);
-  return offset ? this.bb.readInt64(this.bb.__vector(this.bb_pos + offset) + index * 8) : this.bb.createLong(0, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 68);
+  return offset ? this.bb!.readInt64(this.bb!.__vector(this.bb_pos + offset) + index * 8) : this.bb!.createLong(0, 0);
 };
 
 /**
  * @returns {number}
  */
 vectorOfLongsLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 68);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 68);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -1379,24 +1379,24 @@ vectorOfLongsLength():number {
  * @returns {number}
  */
 vectorOfDoubles(index: number):number|null {
-  var offset = this.bb.__offset(this.bb_pos, 70);
-  return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 70);
+  return offset ? this.bb!.readFloat64(this.bb!.__vector(this.bb_pos + offset) + index * 8) : 0;
 };
 
 /**
  * @returns {number}
  */
 vectorOfDoublesLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 70);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 70);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
  * @returns {Float64Array}
  */
 vectorOfDoublesArray():Float64Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 70);
-  return offset ? new Float64Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 70);
+  return offset ? new Float64Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
 };
 
 /**
@@ -1404,8 +1404,8 @@ vectorOfDoublesArray():Float64Array|null {
  * @returns {MyGame.InParentNamespace|null}
  */
 parentNamespaceTest(obj?:MyGame.InParentNamespace):MyGame.InParentNamespace|null {
-  var offset = this.bb.__offset(this.bb_pos, 72);
-  return offset ? (obj || new MyGame.InParentNamespace).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 72);
+  return offset ? (obj || new MyGame.InParentNamespace).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
 };
 
 /**
@@ -1928,7 +1928,7 @@ export class TypeAliases {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -1958,8 +1958,8 @@ static getRootAsTypeAliases(bb:flatbuffers.ByteBuffer, obj?:TypeAliases):TypeAli
  * @returns {number}
  */
 i8():number {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? this.bb.readInt8(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? this.bb!.readInt8(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -1967,13 +1967,13 @@ i8():number {
  * @returns {boolean}
  */
 mutate_i8(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 4);
+  var offset = this.bb!.__offset(this.bb_pos, 4);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt8(this.bb_pos + offset, value);
+  this.bb!.writeInt8(this.bb_pos + offset, value);
   return true;
 };
 
@@ -1981,8 +1981,8 @@ mutate_i8(value:number):boolean {
  * @returns {number}
  */
 u8():number {
-  var offset = this.bb.__offset(this.bb_pos, 6);
-  return offset ? this.bb.readUint8(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 6);
+  return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -1990,13 +1990,13 @@ u8():number {
  * @returns {boolean}
  */
 mutate_u8(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 6);
+  var offset = this.bb!.__offset(this.bb_pos, 6);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint8(this.bb_pos + offset, value);
+  this.bb!.writeUint8(this.bb_pos + offset, value);
   return true;
 };
 
@@ -2004,8 +2004,8 @@ mutate_u8(value:number):boolean {
  * @returns {number}
  */
 i16():number {
-  var offset = this.bb.__offset(this.bb_pos, 8);
-  return offset ? this.bb.readInt16(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 8);
+  return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -2013,13 +2013,13 @@ i16():number {
  * @returns {boolean}
  */
 mutate_i16(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 8);
+  var offset = this.bb!.__offset(this.bb_pos, 8);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt16(this.bb_pos + offset, value);
+  this.bb!.writeInt16(this.bb_pos + offset, value);
   return true;
 };
 
@@ -2027,8 +2027,8 @@ mutate_i16(value:number):boolean {
  * @returns {number}
  */
 u16():number {
-  var offset = this.bb.__offset(this.bb_pos, 10);
-  return offset ? this.bb.readUint16(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 10);
+  return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -2036,13 +2036,13 @@ u16():number {
  * @returns {boolean}
  */
 mutate_u16(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 10);
+  var offset = this.bb!.__offset(this.bb_pos, 10);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint16(this.bb_pos + offset, value);
+  this.bb!.writeUint16(this.bb_pos + offset, value);
   return true;
 };
 
@@ -2050,8 +2050,8 @@ mutate_u16(value:number):boolean {
  * @returns {number}
  */
 i32():number {
-  var offset = this.bb.__offset(this.bb_pos, 12);
-  return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 12);
+  return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -2059,13 +2059,13 @@ i32():number {
  * @returns {boolean}
  */
 mutate_i32(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 12);
+  var offset = this.bb!.__offset(this.bb_pos, 12);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt32(this.bb_pos + offset, value);
+  this.bb!.writeInt32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -2073,8 +2073,8 @@ mutate_i32(value:number):boolean {
  * @returns {number}
  */
 u32():number {
-  var offset = this.bb.__offset(this.bb_pos, 14);
-  return offset ? this.bb.readUint32(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 14);
+  return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -2082,13 +2082,13 @@ u32():number {
  * @returns {boolean}
  */
 mutate_u32(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 14);
+  var offset = this.bb!.__offset(this.bb_pos, 14);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint32(this.bb_pos + offset, value);
+  this.bb!.writeUint32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -2096,8 +2096,8 @@ mutate_u32(value:number):boolean {
  * @returns {flatbuffers.Long}
  */
 i64():flatbuffers.Long {
-  var offset = this.bb.__offset(this.bb_pos, 16);
-  return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 16);
+  return offset ? this.bb!.readInt64(this.bb_pos + offset) : this.bb!.createLong(0, 0);
 };
 
 /**
@@ -2105,13 +2105,13 @@ i64():flatbuffers.Long {
  * @returns {boolean}
  */
 mutate_i64(value:flatbuffers.Long):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 16);
+  var offset = this.bb!.__offset(this.bb_pos, 16);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt64(this.bb_pos + offset, value);
+  this.bb!.writeInt64(this.bb_pos + offset, value);
   return true;
 };
 
@@ -2119,8 +2119,8 @@ mutate_i64(value:flatbuffers.Long):boolean {
  * @returns {flatbuffers.Long}
  */
 u64():flatbuffers.Long {
-  var offset = this.bb.__offset(this.bb_pos, 18);
-  return offset ? this.bb.readUint64(this.bb_pos + offset) : this.bb.createLong(0, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 18);
+  return offset ? this.bb!.readUint64(this.bb_pos + offset) : this.bb!.createLong(0, 0);
 };
 
 /**
@@ -2128,13 +2128,13 @@ u64():flatbuffers.Long {
  * @returns {boolean}
  */
 mutate_u64(value:flatbuffers.Long):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 18);
+  var offset = this.bb!.__offset(this.bb_pos, 18);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint64(this.bb_pos + offset, value);
+  this.bb!.writeUint64(this.bb_pos + offset, value);
   return true;
 };
 
@@ -2142,8 +2142,8 @@ mutate_u64(value:flatbuffers.Long):boolean {
  * @returns {number}
  */
 f32():number {
-  var offset = this.bb.__offset(this.bb_pos, 20);
-  return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0;
+  var offset = this.bb!.__offset(this.bb_pos, 20);
+  return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0;
 };
 
 /**
@@ -2151,13 +2151,13 @@ f32():number {
  * @returns {boolean}
  */
 mutate_f32(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 20);
+  var offset = this.bb!.__offset(this.bb_pos, 20);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeFloat32(this.bb_pos + offset, value);
+  this.bb!.writeFloat32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -2165,8 +2165,8 @@ mutate_f32(value:number):boolean {
  * @returns {number}
  */
 f64():number {
-  var offset = this.bb.__offset(this.bb_pos, 22);
-  return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0.0;
+  var offset = this.bb!.__offset(this.bb_pos, 22);
+  return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0;
 };
 
 /**
@@ -2174,13 +2174,13 @@ f64():number {
  * @returns {boolean}
  */
 mutate_f64(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 22);
+  var offset = this.bb!.__offset(this.bb_pos, 22);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeFloat64(this.bb_pos + offset, value);
+  this.bb!.writeFloat64(this.bb_pos + offset, value);
   return true;
 };
 
@@ -2189,24 +2189,24 @@ mutate_f64(value:number):boolean {
  * @returns {number}
  */
 v8(index: number):number|null {
-  var offset = this.bb.__offset(this.bb_pos, 24);
-  return offset ? this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 24);
+  return offset ? this.bb!.readInt8(this.bb!.__vector(this.bb_pos + offset) + index) : 0;
 };
 
 /**
  * @returns {number}
  */
 v8Length():number {
-  var offset = this.bb.__offset(this.bb_pos, 24);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 24);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
  * @returns {Int8Array}
  */
 v8Array():Int8Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 24);
-  return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 24);
+  return offset ? new Int8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
 };
 
 /**
@@ -2214,24 +2214,24 @@ v8Array():Int8Array|null {
  * @returns {number}
  */
 vf64(index: number):number|null {
-  var offset = this.bb.__offset(this.bb_pos, 26);
-  return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 26);
+  return offset ? this.bb!.readFloat64(this.bb!.__vector(this.bb_pos + offset) + index * 8) : 0;
 };
 
 /**
  * @returns {number}
  */
 vf64Length():number {
-  var offset = this.bb.__offset(this.bb_pos, 26);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 26);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
  * @returns {Float64Array}
  */
 vf64Array():Float64Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 26);
-  return offset ? new Float64Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 26);
+  return offset ? new Float64Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
 };
 
 /**
diff --git a/tests/namespace_test/namespace_test1_generated.ts b/tests/namespace_test/namespace_test1_generated.ts
index 54d935a4..31a24350 100644
--- a/tests/namespace_test/namespace_test1_generated.ts
+++ b/tests/namespace_test/namespace_test1_generated.ts
@@ -18,7 +18,7 @@ export class TableInNestedNS {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -48,8 +48,8 @@ static getRootAsTableInNestedNS(bb:flatbuffers.ByteBuffer, obj?:TableInNestedNS)
  * @returns {number}
  */
 foo():number {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -57,13 +57,13 @@ foo():number {
  * @returns {boolean}
  */
 mutate_foo(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 4);
+  var offset = this.bb!.__offset(this.bb_pos, 4);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt32(this.bb_pos + offset, value);
+  this.bb!.writeInt32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -101,7 +101,7 @@ export class StructInNestedNS {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -122,7 +122,7 @@ __init(i:number, bb:flatbuffers.ByteBuffer):StructInNestedNS {
  * @returns {number}
  */
 a():number {
-  return this.bb.readInt32(this.bb_pos);
+  return this.bb!.readInt32(this.bb_pos);
 };
 
 /**
@@ -130,13 +130,13 @@ a():number {
  * @returns {boolean}
  */
 mutate_a(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 0);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt32(this.bb_pos + offset, value);
+  this.bb!.writeInt32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -144,7 +144,7 @@ mutate_a(value:number):boolean {
  * @returns {number}
  */
 b():number {
-  return this.bb.readInt32(this.bb_pos + 4);
+  return this.bb!.readInt32(this.bb_pos + 4);
 };
 
 /**
@@ -152,13 +152,13 @@ b():number {
  * @returns {boolean}
  */
 mutate_b(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 4);
+  var offset = this.bb!.__offset(this.bb_pos, 4);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt32(this.bb_pos + offset, value);
+  this.bb!.writeInt32(this.bb_pos + offset, value);
   return true;
 };
 
diff --git a/tests/namespace_test/namespace_test2_generated.ts b/tests/namespace_test/namespace_test2_generated.ts
index 8a4aebd0..18f1d6e8 100644
--- a/tests/namespace_test/namespace_test2_generated.ts
+++ b/tests/namespace_test/namespace_test2_generated.ts
@@ -1,6 +1,6 @@
 // automatically generated by the FlatBuffers compiler, do not modify
 
-import * as NS11563891686210618450 from "./namespace_test1_generated";
+import * as NS9459827973991502386 from "./namespace_test1_generated";
 /**
  * @constructor
  */
@@ -9,7 +9,7 @@ export class TableInFirstNS {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -39,31 +39,31 @@ static getRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:TableInFirstNS):T
  * @param {NamespaceA.NamespaceB.TableInNestedNS=} obj
  * @returns {NamespaceA.NamespaceB.TableInNestedNS|null}
  */
-fooTable(obj?:NS11563891686210618450.NamespaceA.NamespaceB.TableInNestedNS):NS11563891686210618450.NamespaceA.NamespaceB.TableInNestedNS|null {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? (obj || new NS11563891686210618450.NamespaceA.NamespaceB.TableInNestedNS).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+fooTable(obj?:NS9459827973991502386.NamespaceA.NamespaceB.TableInNestedNS):NS9459827973991502386.NamespaceA.NamespaceB.TableInNestedNS|null {
+  var offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? (obj || new NS9459827973991502386.NamespaceA.NamespaceB.TableInNestedNS).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
 };
 
 /**
  * @returns {NamespaceA.NamespaceB.EnumInNestedNS}
  */
-fooEnum():NS11563891686210618450.NamespaceA.NamespaceB.EnumInNestedNS {
-  var offset = this.bb.__offset(this.bb_pos, 6);
-  return offset ? /** @type {NamespaceA.NamespaceB.EnumInNestedNS} */ (this.bb.readInt8(this.bb_pos + offset)) : NS11563891686210618450.NamespaceA.NamespaceB.EnumInNestedNS.A;
+fooEnum():NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS {
+  var offset = this.bb!.__offset(this.bb_pos, 6);
+  return offset ? /** @type {NamespaceA.NamespaceB.EnumInNestedNS} */ (this.bb!.readInt8(this.bb_pos + offset)) : NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS.A;
 };
 
 /**
  * @param {NamespaceA.NamespaceB.EnumInNestedNS} value
  * @returns {boolean}
  */
-mutate_foo_enum(value:NS11563891686210618450.NamespaceA.NamespaceB.EnumInNestedNS):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 6);
+mutate_foo_enum(value:NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS):boolean {
+  var offset = this.bb!.__offset(this.bb_pos, 6);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt8(this.bb_pos + offset, value);
+  this.bb!.writeInt8(this.bb_pos + offset, value);
   return true;
 };
 
@@ -71,9 +71,9 @@ mutate_foo_enum(value:NS11563891686210618450.NamespaceA.NamespaceB.EnumInNestedN
  * @param {NamespaceA.NamespaceB.StructInNestedNS=} obj
  * @returns {NamespaceA.NamespaceB.StructInNestedNS|null}
  */
-fooStruct(obj?:NS11563891686210618450.NamespaceA.NamespaceB.StructInNestedNS):NS11563891686210618450.NamespaceA.NamespaceB.StructInNestedNS|null {
-  var offset = this.bb.__offset(this.bb_pos, 8);
-  return offset ? (obj || new NS11563891686210618450.NamespaceA.NamespaceB.StructInNestedNS).__init(this.bb_pos + offset, this.bb) : null;
+fooStruct(obj?:NS9459827973991502386.NamespaceA.NamespaceB.StructInNestedNS):NS9459827973991502386.NamespaceA.NamespaceB.StructInNestedNS|null {
+  var offset = this.bb!.__offset(this.bb_pos, 8);
+  return offset ? (obj || new NS9459827973991502386.NamespaceA.NamespaceB.StructInNestedNS).__init(this.bb_pos + offset, this.bb!) : null;
 };
 
 /**
@@ -95,8 +95,8 @@ static addFooTable(builder:flatbuffers.Builder, fooTableOffset:flatbuffers.Offse
  * @param {flatbuffers.Builder} builder
  * @param {NamespaceA.NamespaceB.EnumInNestedNS} fooEnum
  */
-static addFooEnum(builder:flatbuffers.Builder, fooEnum:NS11563891686210618450.NamespaceA.NamespaceB.EnumInNestedNS) {
-  builder.addFieldInt8(1, fooEnum, NS11563891686210618450.NamespaceA.NamespaceB.EnumInNestedNS.A);
+static addFooEnum(builder:flatbuffers.Builder, fooEnum:NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS) {
+  builder.addFieldInt8(1, fooEnum, NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS.A);
 };
 
 /**
@@ -126,7 +126,7 @@ export class TableInC {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -157,8 +157,8 @@ static getRootAsTableInC(bb:flatbuffers.ByteBuffer, obj?:TableInC):TableInC {
  * @returns {NamespaceA.TableInFirstNS|null}
  */
 referToA1(obj?:NamespaceA.TableInFirstNS):NamespaceA.TableInFirstNS|null {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? (obj || new NamespaceA.TableInFirstNS).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? (obj || new NamespaceA.TableInFirstNS).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
 };
 
 /**
@@ -166,8 +166,8 @@ referToA1(obj?:NamespaceA.TableInFirstNS):NamespaceA.TableInFirstNS|null {
  * @returns {NamespaceA.SecondTableInA|null}
  */
 referToA2(obj?:NamespaceA.SecondTableInA):NamespaceA.SecondTableInA|null {
-  var offset = this.bb.__offset(this.bb_pos, 6);
-  return offset ? (obj || new NamespaceA.SecondTableInA).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 6);
+  return offset ? (obj || new NamespaceA.SecondTableInA).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
 };
 
 /**
@@ -212,7 +212,7 @@ export class SecondTableInA {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -243,8 +243,8 @@ static getRootAsSecondTableInA(bb:flatbuffers.ByteBuffer, obj?:SecondTableInA):S
  * @returns {NamespaceC.TableInC|null}
  */
 referToC(obj?:NamespaceC.TableInC):NamespaceC.TableInC|null {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? (obj || new NamespaceC.TableInC).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? (obj || new NamespaceC.TableInC).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
 };
 
 /**
diff --git a/tests/union_vector/union_vector_generated.ts b/tests/union_vector/union_vector_generated.ts
index 62e31054..65cf15b6 100644
--- a/tests/union_vector/union_vector_generated.ts
+++ b/tests/union_vector/union_vector_generated.ts
@@ -20,7 +20,7 @@ export class Attacker {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -50,8 +50,8 @@ static getRootAsAttacker(bb:flatbuffers.ByteBuffer, obj?:Attacker):Attacker {
  * @returns {number}
  */
 swordAttackDamage():number {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
 };
 
 /**
@@ -59,13 +59,13 @@ swordAttackDamage():number {
  * @returns {boolean}
  */
 mutate_sword_attack_damage(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 4);
+  var offset = this.bb!.__offset(this.bb_pos, 4);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt32(this.bb_pos + offset, value);
+  this.bb!.writeInt32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -101,7 +101,7 @@ export class Rapunzel {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -122,7 +122,7 @@ __init(i:number, bb:flatbuffers.ByteBuffer):Rapunzel {
  * @returns {number}
  */
 hairLength():number {
-  return this.bb.readInt32(this.bb_pos);
+  return this.bb!.readInt32(this.bb_pos);
 };
 
 /**
@@ -130,13 +130,13 @@ hairLength():number {
  * @returns {boolean}
  */
 mutate_hair_length(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 0);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt32(this.bb_pos + offset, value);
+  this.bb!.writeInt32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -159,7 +159,7 @@ export class BookReader {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -180,7 +180,7 @@ __init(i:number, bb:flatbuffers.ByteBuffer):BookReader {
  * @returns {number}
  */
 booksRead():number {
-  return this.bb.readInt32(this.bb_pos);
+  return this.bb!.readInt32(this.bb_pos);
 };
 
 /**
@@ -188,13 +188,13 @@ booksRead():number {
  * @returns {boolean}
  */
 mutate_books_read(value:number):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 0);
+  var offset = this.bb!.__offset(this.bb_pos, 0);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeInt32(this.bb_pos + offset, value);
+  this.bb!.writeInt32(this.bb_pos + offset, value);
   return true;
 };
 
@@ -217,7 +217,7 @@ export class Movie {
   /**
    * @type {flatbuffers.ByteBuffer}
    */
-  bb: flatbuffers.ByteBuffer;
+  bb: flatbuffers.ByteBuffer|null = null;
 
   /**
    * @type {number}
@@ -255,8 +255,8 @@ static bufferHasIdentifier(bb:flatbuffers.ByteBuffer):boolean {
  * @returns {Character}
  */
 mainCharacterType():Character {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? /** @type {Character} */ (this.bb.readUint8(this.bb_pos + offset)) : Character.NONE;
+  var offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? /** @type {Character} */ (this.bb!.readUint8(this.bb_pos + offset)) : Character.NONE;
 };
 
 /**
@@ -264,13 +264,13 @@ mainCharacterType():Character {
  * @returns {boolean}
  */
 mutate_main_character_type(value:Character):boolean {
-  var offset = this.bb.__offset(this.bb_pos, 4);
+  var offset = this.bb!.__offset(this.bb_pos, 4);
 
   if (offset === 0) {
     return false;
   }
 
-  this.bb.writeUint8(this.bb_pos + offset, value);
+  this.bb!.writeUint8(this.bb_pos + offset, value);
   return true;
 };
 
@@ -279,8 +279,8 @@ mutate_main_character_type(value:Character):boolean {
  * @returns {?flatbuffers.Table}
  */
 mainCharacter<T extends flatbuffers.Table>(obj:T):T|null {
-  var offset = this.bb.__offset(this.bb_pos, 6);
-  return offset ? this.bb.__union(obj, this.bb_pos + offset) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 6);
+  return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null;
 };
 
 /**
@@ -288,24 +288,24 @@ mainCharacter<T extends flatbuffers.Table>(obj:T):T|null {
  * @returns {Character}
  */
 charactersType(index: number):Character|null {
-  var offset = this.bb.__offset(this.bb_pos, 8);
-  return offset ? /** @type {Character} */ (this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index)) : /** @type {Character} */ (0);
+  var offset = this.bb!.__offset(this.bb_pos, 8);
+  return offset ? /** @type {Character} */ (this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index)) : /** @type {Character} */ (0);
 };
 
 /**
  * @returns {number}
  */
 charactersTypeLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 8);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 8);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
  * @returns {Uint8Array}
  */
 charactersTypeArray():Uint8Array|null {
-  var offset = this.bb.__offset(this.bb_pos, 8);
-  return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 8);
+  return offset ? new Uint8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
 };
 
 /**
@@ -314,16 +314,16 @@ charactersTypeArray():Uint8Array|null {
  * @returns {?flatbuffers.Table}
  */
 characters<T extends flatbuffers.Table>(index: number, obj:T):T|null {
-  var offset = this.bb.__offset(this.bb_pos, 10);
-  return offset ? this.bb.__union(obj, this.bb.__vector(this.bb_pos + offset) + index * 4) : null;
+  var offset = this.bb!.__offset(this.bb_pos, 10);
+  return offset ? this.bb!.__union(obj, this.bb!.__vector(this.bb_pos + offset) + index * 4) : null;
 };
 
 /**
  * @returns {number}
  */
 charactersLength():number {
-  var offset = this.bb.__offset(this.bb_pos, 10);
-  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
+  var offset = this.bb!.__offset(this.bb_pos, 10);
+  return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
 };
 
 /**
-- 
GitLab