Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript declarations? #233

Open
brundonsmith opened this issue Jan 31, 2019 · 13 comments
Open

TypeScript declarations? #233

brundonsmith opened this issue Jan 31, 2019 · 13 comments

Comments

@brundonsmith
Copy link

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.

@kripken
Copy link
Owner

kripken commented Jan 31, 2019

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

@devmattrick
Copy link

This may be of interest: https://github.com/charto/nbind

@brundonsmith
Copy link
Author

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

@brundonsmith
Copy link
Author

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?

@brundonsmith
Copy link
Author

brundonsmith commented Mar 19, 2019

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?

@giniedp
Copy link

giniedp commented Sep 19, 2019

@kripken is there any progress or plans on this? I would love to see a .d.ts coming straight from the ammo.js repository.

@kripken
Copy link
Owner

kripken commented Sep 19, 2019

There is some work in emscripten on typescript declaration support, which may eventually be relevant here, but nothing yet (emscripten-core/emscripten#7083 (comment)).

@kripken
Copy link
Owner

kripken commented Sep 19, 2019

We would definitely appreciate contributions in that area!

@giniedp
Copy link

giniedp commented Sep 20, 2019

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.

@giniedp
Copy link

giniedp commented Sep 22, 2019

so i have an example on stackblitz out now
https://stackblitz.com/edit/ammojs-typed-falling-cubes

@kripken
Copy link
Owner

kripken commented Sep 23, 2019

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!

@giniedp
Copy link

giniedp commented Jul 12, 2020

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)

@bihongbin3027
Copy link

ammojs-typed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants