Ubuntu 17.10下FlatBuffer include语句对enum无效的技术问询
include语句支持Enum等所有数据类型,你的问题大概率是编译配置或版本问题 Hey there! First off, let me clear this up right away: FlatBuffers' include statement absolutely supports all data types—not just tables. Enums, structs, unions, and even other type definitions are all fair game for inclusion and reuse across schema files. So your issue isn't that include doesn't work with enums, but rather something else in your setup or compilation process.
Let's walk through the most likely causes and fixes, since you already have experience getting included tables working:
Double-check your schema include syntax and paths
Make sure the path to your enum-containing.fbsfile is correct relative to where you're runningflatc, or use the--include-pathsflag to tellflatcwhere to look for dependent schemas. For example:flatc --ts --include-paths ./schemas main.fbsAlso, ensure your enum is defined properly in the included file (no typos, correct scope—if it's in a namespace, you'll need to reference it with that namespace in TypeScript).
Verify you're compiling all dependent schemas
Sometimes when usinginclude, you need to pass all related.fbsfiles toflatcexplicitly, not just your main schema. For example, if your main schema isapp.fbsand it includescommon_enums.fbs, run:flatc --ts common_enums.fbs app.fbsIf you only pass
app.fbs, older versions offlatc(like 1.7 you're using) might not automatically process the included enum file, leading to missing TypeScript definitions.Inspect the generated TypeScript code
Take a look at the.tsfiles generated byflatc. Do you see your enum's definition anywhere? If it's missing, that confirmsflatcdidn't process the included enum file. If it is present, make sure you're importing/using it correctly in your code (e.g., if it's in a namespace likeMyApp.Common, you'd reference it asMyApp.Common.MyEnum).Consider upgrading your flatc version
FlatBuffers 1.7 is quite outdated at this point—there have been dozens of fixes and improvements to TypeScript code generation since then, including better handling of included types. Upgrading to a more recent version (even a 1.x patch release) might resolve the issue outright.
Since you've already gotten included tables working, the core include mechanism is functioning for you—focus on the above steps to get your enums loading properly.
内容的提问来源于stack exchange,提问作者Jason Fitch

