diff --git a/CMakeLists.txt b/CMakeLists.txt index 93dfc58bd..46bb734d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -369,6 +369,8 @@ else() $<$: -Werror # Treat all compiler warnings as errors + -fno-rtti # Disable runtime type information + $<$: # False positive string overflow # https://github.com/google/flatbuffers/issues/7366 diff --git a/src/idl_gen_ts.cpp b/src/idl_gen_ts.cpp index 0b470991a..042bbba55 100644 --- a/src/idl_gen_ts.cpp +++ b/src/idl_gen_ts.cpp @@ -38,6 +38,12 @@ struct ImportDefinition { }; enum AnnotationType { kParam = 0, kType = 1, kReturns = 2 }; + +template bool SupportsObjectAPI() { return false; } + +// Structs can have Object API support. +template<> bool SupportsObjectAPI() { return true; } + } // namespace namespace ts { @@ -712,9 +718,9 @@ class TsGenerator : public BaseGenerator { return symbols_expression; } - template + template ImportDefinition AddImport(import_set &imports, const Definition &dependent, - const DefintionT &dependency) { + const DefinitionT &dependency) { // The unique name of the dependency, fully qualified in its namespace. const std::string unique_name = GetTypeName( dependency, /*object_api = */ false, /*force_ns_wrap=*/true); @@ -748,8 +754,9 @@ class TsGenerator : public BaseGenerator { // Strip the leading // .substr(2); flat_file_import_declarations_[file][import_name] = name; + if (parser_.opts.generate_object_based_api && - typeid(dependency) == typeid(StructDef)) { + SupportsObjectAPI()) { flat_file_import_declarations_[file][import_name + "T"] = object_name; } }