TypeScript declarations?
It would be awesome to have TypeScript declarations available. I don't know if these would have to be created manually or if they could somehow be scraped from the C++ ones, but I'd think the latter could be done at least as a starting point.
Interesting idea! I think we could best do this by modifying the webidl binder in emscripten, so that as it generates all the glue C++ and JS (from the webidl file) it can also emit a TypeScript file on the side.
The tool is here if someone wants to try (let me know if you have questions): https://github.com/emscripten-core/emscripten/blob/incoming/tools/webidl_binder.py
This may be of interest: https://github.com/charto/nbind
I've written a preliminary Node program which attempts to scrape the Bullet docs online and generate Ammo.js type declarations. It still has issues, but anecdotally it appears to get 60%-80% correct so far.
https://github.com/brundonsmith/ammo-scraper
Question: how are namespaces represented in the JS version? It seemed like, from the WebIDL docs, you can just replace :: with _ in the member names? Is that correct?
I ended up finding that I should just strip the namespaces altogether.
In its current state, this set of types more or less correctly types the terrain example script. The exceptions are Ammo._malloc and Ammo.HEAPF32. Are these WebIDL artifacts? Do they just mirror C++ built-in constructs?
@kripken is there any progress or plans on this? I would love to see a .d.ts coming straight from the ammo.js repository.
There is some work in emscripten on typescript declaration support, which may eventually be relevant here, but nothing yet (https://github.com/emscripten-core/emscripten/issues/7083#issuecomment-531224615).
We would definitely appreciate contributions in that area!
thx. I've been working on a .idl -> .d.ts generator in the past hours. This is my progress so far
https://github.com/giniedp/ammojs-typed
I had to make some adjustments to the idl to make it work. All steps are described in the readme. I am planning a more thorough integration check and a couple examples, maybe hosted on https://stackblitz.com
However the embind approach seems to be more reasonable. I'd have a look into it too.
so i have an example on stackblitz out now https://stackblitz.com/edit/ammojs-typed-falling-cubes
That's a cool idea @giniedp! That would make more sense for ammo actually, since we don't use embind.
Might be worth opening an issue on emscripten as other people might be interested in this too. I'd definitely like to see something like this in emscripten myself, sounds very useful!
Finally had some time and made progress.
Here is a tool that you can use to generate declarations for emscripten modules (or browser libs if you wish) https://github.com/giniedp/webidl2ts
The https://github.com/giniedp/ammojs-typed project is upgraded so it uses that tool. Basically all work that ammojs-typed does can be migrated to this project with ease. It boils down to a simple command that can be run after emscripten modules have been generated (see the generate command here). There is just a little idl adjustment needed before doing so (see Readme)
ammojs-typed