Babylon js typescript to flow

Has anyone tried using Babylon.d.ts to generate a babylon.js.flow file yet? If so, I am curious what options you guys end up using for flow generation.

I use flowgen 1.14.1 (GitHub - joarwilk/flowgen: Generate flowtype definition files from TypeScript) to generate the flow file and I end up using " --add-flow-header --no-jsdoc". This works mostly but ends up screwing up pieces with interface class in the typescript that extend from other types. I end up with no semi-colon everywhere there is an interface decleration.

And if use the --interface-records, which is supposed to convert to exact objects, this ends up declaring $Exact in a bunch places where interfaces are defined. Any ideas on how to beat this?


I have no clue on flow on my side but do not hesitate to share the answer if you find it as it might help others in the community :slight_smile:


To start with I have no experience generating flow files. I used flow on one project, but then switched over to TypeScript.

I’ve used babylon.d.ts to generate another library using ts-morph ( dsherret/ts-morph: TypeScript Compiler API wrapper for static analysis and programmatic code changes. ( I’m absolutely not suggesting you go that route to generate flow files, but just sharing why I am replying to your question.

The places I had trouble were when classes/interfaces were extended (ie: some Scene observables, Mesh instancedBuffers). If you can share how the flow generation fails then I maybe we can hand code what is missing? It looks like the library you have chosen has difficulties with namespaces (and I had some trouble there initially as well)…

Thanks for the reply. I have troubles in exactly the same places. That’s when classes/interfaces were extended. Initially I thought this problem was with all extends. But then it came down to two specific cases and not sure I understood the reason for one of them.

  1. class X extends Basic_class like Event, EventInit, etc. This for some reasons produces a type in flow that doesn’t union with the extended class. And that leads to a few syntax errors. I don’t understand this one, but I was able to hand clean them up.

  2. class X extends Y implements Z. This is the major problem, as I see 300+ of these (or maybe some of them are unrelated). In flow this gets converted to declare class X mixins Y, Z when using Flowgen and I don’t think that is a thing. What should happen probably is that flowgen creates a type Y & Z which then get’s extended by X or unioned with X. Do you think that I should hand fix the flow or is there something we can do on the .d.ts file instead to avoid this pattern?


1 Like

There are some interesting things going on for sure. the babylon project even has interfaces that extend classes, which is perfectly legal in TypeScript. Coming from regular OOP like c#/java I was surprised initially and I needed to commit to the tsmorph project to be able to work with some of those constructs to generate from babylon.d.ts. I needed to explicitly look for specific places where the Scene prototype is changed:
Babylon.js/physicsEngineComponent.ts at master · BabylonJS/Babylon.js (

In order to find those programatically I needed to look through the interfaces defined in the module. Is that a problem area for your generation or can you share more some code points that aren’t generating properly? Maybe a repo that has a working example that generates the file with errors?