flatbuffers
flatbuffers copied to clipboard
[TS] Regression in generating from simple schema
When upgrading from flatc version 2.0.0 to 2.0.5 it no longer correctly generates proper typescript code. Using the schema below (datapoint.fbs) data.ts and datapoint.ts files are generated. data.ts contains usable code but imports datapoint.ts. datapoint.ts only contains a single line, a reference to itself.
datapoint.fbs
struct Datapoint {
t: int64;
o: float64;
h: float64;
l: float64;
c: float64;
v: float64;
w: float64;
}
table Data {
datapoints: [Datapoint];
}
root_type Data;
$ flatc --ts datapoint.fbs
Generated datapoint.ts
export { Datapoint } from './datapoint';
@krojew for ts support
I tried to reproduce it myself and it seems to me that the problem is a name collision. The generated files include${your_schema}.ts and ${your_type[i]}.ts for each of your types. The type Datapoint and the schema file name datapoint.fbs both try to generate datapoint.ts and collide.
A simple workaround would be to rename your schema file. My 2c for a fix would be that the file with the export should be called datapoint.fbs.ts or datapoint_generated.ts or something that's harder to collide with.
I think I am seeing the same issue when trying to create the ts code for Apache Arrow.
FWIW, the single-file ts codegen flag I created for #7161 would allow you to work around this, although it does actually generate self-imports (although they are at least correct self-imports), but I imagine that swapping to that would be more work than getting the relevant codegen fixed for this case.
Seems like making the top-level generated file for typescript have a _generated (well, whatever the contents are of --filename-suffix are, more precisely) suffix would be desirable, though.
#7098
@krojew @CasperN Can you take a look at this regression?
@bjornharrtell could you take a look at this. It's preventing me from upgrading flatbuffers in Apache Arrow.
@domoritz would like to but unlikely to be able to prioritize this in near future. You are welcome to work on it yourself.
@domoritz I have a fix up.