-
Notifications
You must be signed in to change notification settings - Fork 85
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
Feature typescript typegen #55
Conversation
This is great! Thanks for the contribution - I've been wanting to add typedefs for TS and Flow for a bit, but hadn't considered this approach. The build is currently failing because the generated README file has changed due to JSDoc changes (specifically the module name Assuming that we'd like to gen typedefs without changing the docs, I think either the code might need pre-processing, or the README or typedef might need post-processing... I think the easiest might be changing the command for docs generation to pipe through
Open to better options if you have one - this only fixes worst doc issue, but it's probably sufficient. |
Sorry, just gave you a merge conflict as well - you'll need to rebase to master.
I'm not sure what the standard approach here is, but I'm happy to include the typedefs in the dist if that's appropriate for TS users. Now I'm wondering whether we can do this for Flow too. |
Hm, I hadn't considered the generated docs. I can see the H3Index type also adds another layer to the table-of-contents which seems unnecessary. I like your idea of pre- or post-processing. I'll try finding a solution that doesn't change the docs. The think the standard approaches for non-typescript projects is either bundling it yourself or leaving it to userland to provide them through the DefinatelyTyped project. The first approach is preferable IMO. Side note: Have you considered distributing the library simply as 'h3' on npm? Putting 'js' or 'node' in the package name is discouraged. |
The name was taken. It's now deprecated, but would probably require some work (and invoke some potential confusion) to try to take it over. I also think the |
One other idea here is that you could concatenate either source or TS code during the generation process to shim in missing defs. |
I was not aware of the separate N-API module. Seems like a natural way to go then 👍 I've rebased and moved the module renaming to a simple pipe through I also added a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Thanks for the contribution!
@@ -103,6 +103,7 @@ const coordinates = h3.h3SetToMultiPolygon(hexagons, true); | |||
* [.getRes0Indexes()](#module_h3.getRes0Indexes) ⇒ <code>Array.<H3Index></code> | |||
* [.degsToRads(deg)](#module_h3.degsToRads) ⇒ <code>Number</code> | |||
* [.radsToDegs(rad)](#module_h3.radsToDegs) ⇒ <code>Number</code> | |||
* [.H3Index](#module_h3.H3Index) : <code>string</code> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL :). This works for me.
"source": "lib/h3core.js", | ||
"scripts": { | ||
"build-update-h3": "bash scripts/update-h3.sh", | ||
"build-emscripten": "yarn build-update-h3 && yarn docker-emscripten", | ||
"build-docs": "jsdoc2md --global-index-format grouped --partial doc-files/scope.hbs --helper ./doc-files/insert-version.js --separators --template doc-files/README.tmpl.md lib/h3core.js > README.md", | ||
"build-tsd": "jsdoc -t node_modules/tsd-jsdoc/dist -d console lib/h3core.js | sed 's/\"h3\"/\"h3-js\"/g' > dist/types.d.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I needed typescript definitions for these bindings and noticed you generate your README off of jsdoc.
I've managed to generate the definitions using
tsd-jsdoc
requiring minimal change toh3core.js
.This PR adds the required jsdoc changes, but also a script to bundle the types on
prepublish
.I'm not sure how you feel about distributing these definitions yourself. If you'd rather not, I'll simply remove that part. But I do hope you'll allow the jsdoc changes. 😃