Sharing this here to get ahead of any potentially duplicated efforts:
I’ve started building out a .d.ts file for the rhino3dm.js library (progress here). I’m just adding things as they come up for now. Will submit it through DefinitelyTyped if we manage to finish it.
Excited about all this web stuff. But I do miss C# keeping me in line. Happy we have typescript, at least.
Rolling List of Pending Fixes:
File3dm does not declare any output types for its methods ( like objects() and layers() )
File3dmLayerTable.count() output as void return type
GeometryBase.getBoundingBox() is generated with an argument for accurate but the javascript call fails if the argument is provided.
I was playing around with this and am happy to help. If we can get a sample up of a few namspaces and methods that would be a good start.
I see your sample, would it also be worth including the comments in the functions? Those comments may come from a different source, but we may be able to automate that.
We have tools to batch convert the source once a pattern is established.
Great news, thanks! No urgency from my end, was a good learning experience. Will keep it limited to things I just need for now.
The only non-copying work done was declaring the require('rhino3dm').then() situation in a way that lets the typescript syntax match the examples. And finding the esmoduleinterop flag. Not sure if it’s “right” but it works.
It’s probably best for me to get the generator written now as I’ll need your input on how to make and use these declaration files. I’m not very familiar with them. It’s also a good excuse to put the python equivalent (stubs) at the same time. Hopefully I’ll have something we can all look at in a day or so.
Here’s where I got to today. The rhino3dm github repository contains a project at rhino3dm/src/docgen/docgen.sln
This project is a console application that parses both the C++ and C# code to auto-generate api docs as well as a typescript definition. Pretty quick and hacky at this point, but I did get pretty far. When the application executes it creates a rhino3dm.ts.d file in /rhino3dm/src/docgen/out/js_tsdef. Here’s what it is generating so far.
3000+ lines of auto-generated fun.
All of the logic is in the JavascriptClass.GenerateTypescriptDefinition function. Please feel free to run it and see if anything can be added to it.
I just added all of the enums to the declaration file and provided type information for the parameters. The gist above should contain the updated data.
Thanks, I’ll check out the PR. I’m not sure about adding constructors yet as I haven’t figured out a good way to expose overloaded constructors in rhino3dm.js (never mind )
(General disclaimer that I left them in that way in my version because typescript didn’t complain. Not sure what best practice is.)
I’m going to keep a rolling list of the little finds at the top of this thread unless a better place comes up. Some of the File3dm functionality didn’t make it through.