Rhino3dm.js typescript declaration file

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.
1 Like

Great! Have not properly looked at this, but it looked interesting: https://github.com/microsoft/dts-gen

1 Like

Will definitely be tinkering with this, thanks! Writing out the whole thing by hand felt a bit terrifying.


/** Declaration file generated by dts-gen */

export = rhino3dm;

declare function rhino3dm(rhino3dm: any, ...args: any[]): any;

It doesn’t seem to want to go much deeper. Will keep trying

Yeah, I’ve never looked at automating the generation of the typings in earnest, but it seems something that reasonable people do out there.

@scottd isn’t this something you were tinkering with when you were last in Barcelona?

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.

This can be autogenerated; I just haven’t spent the time to figure out the syntax. Thanks for getting this started @Chuck_Driesler

I have an application that analyzes the javascript source code as well as parses the C# RhinoCommon related code to autogenerate the javascript help.

This code can be adapted to autogenerate the .d.ts file as well.

Don’t spend too much time putting this together by hand; I’ll try to get a code together for autogeneration asap.

We can build a richer typescript definition file ourselves. I’ve been meaning to get back to this project; maybe it’s time :slight_smile:

1 Like

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.

1 Like

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.

@Chuck_Driesler, beginner question… how do you actually use this typescript declaration file?

:slight_smile: Nevermind, I figured it out. Just needed to get the @types directory in the right spot in my node test project.

1 Like

Here’s where I got to today. The rhino3dm github repository contains a project at
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.


Amazing, thanks! Will give it a spin today and report back here

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.

1 Like

Everything looks really great, save a few straggling C# types making it through (am still tracking these).

I just submitted a pull request with a few missing pieces (handling the promise, and constructors) here. Output available here:

1 Like

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 :slight_smile: )

1 Like

(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.

@will it would be good to add this to npm when you submit new versions of rhino3dm.js

1 Like

Just published rhino3dm@0.5.0.

Hopefully it works!

What about the rhino3dm.d.ts file?