futurGH / ts-to-jsdoc

Transpile TypeScript code to fully compatible JavaScript + JSDoc comments.
MIT License
181 stars 17 forks source link

Is it possible to take `.d.ts` + `.js` to output -> JSDoc-style `.js`? #18

Closed matthew-dean closed 1 year ago

matthew-dean commented 1 year ago

I assume this tool can't do this, but I'm wondering if you might know how to go about it.

For instance, I'm looking at a repo that has each .js file documented with a .d.ts file, which I'd like to merge.

futurGH commented 1 year ago

Doing that would be fairly different from how ts-to-jsdoc works. The library used internally, ts-morph, should be able to read & parse .d.ts source files (but don't quote me on that) — I'm not sure how you'd translate a symbol between them and JS files though.

It's worth checking if ts-morph can handle .js/.d.ts projects with allowJs in the configuration, but if it can't, your best bet would probably be parsing out comments with ts-morph and using something like https://github.com/acornjs/acorn to write them to the corresponding JS files.