futurGH/ts-to-jsdoc

Support Javascript as input

Closed this issue · 9 comments

Allow to use Javascript files as input, filling JsDoc comments with types inferred from their dependencies. I'm not worried too much about having a lot of any types as far as it generates the JsDoc comments with all parameters and return type, so later I can keep improving them by hand. If possible, do it replacing the actual files in place. Is that possible? Does it falls on scope of this project? If not, is there any one that can do this? I would not like to move to Typescript just for typing, and creating all the JsDoc comments by hand is tyring...

If I'm understanding correctly, this sounds like something your editor should be capable of doing? JetBrains IDEs have Infer JSDoc from usage, VS Code is also capable of generating JSDoc for you.

It's not the same, IDE support is just helpers to add JsDoc comments, one by one. What I want is a CLI tool that can add all of them at once (modules, classes, methods, variables...), also if being redundant, and since ts-to-jsdoc can do it from TypeScript code by inferring the types, do the same with Javascript files.

Gotcha.
@piranna Does an extension like Document This cover that? I'm not opposed to implementing this (depending on how useful the type info we can get out of a JS file even is), but I want to make sure existing work isn't being unnecessarily duplicated.

Does an extension like Document This cover that?

Almost! :-) It seems the logic is there, in fact it also detect and fills the Typescript interface in the function argument, but you need to go over all classes, modules, functions and methods one-by-one, instead of filling all of them at once. Also the fact that the repo is archived and link to VSCode Marketplace throw a 404 error, it's not a good sign... The points I'm missing on Document This are:

  • fill all possible docs at once, instead of one-by-one
  • being a CLI tool to automate
  • sync and update already available JsDoc entries, specially regarding default values and interpolated types

Does this makes sense?

Whoops, I meant to link to this fork that does appear to be actively maintained ;)

That definitely makes sense. I do want to note that point 3 may or may not fit ts-to-jsdoc as is; it's written to assume there aren't already any types in doc comments as is. I'll take a look at how much value implementing this would create.

Yeah, point 3 would be more difficult to implement, since we would need to parse and merge current JsDoc strings too. Just by adding new ones would be enough.

Closing this as out of scope — for the time being, I don't see a tool called ts-to-jsdoc transforming anything other than TS into anything other than JSDoc.

Since Typescript is being sold as an extensión to JavaScript, i see It as being in scope...

You'll have to take that up with Microsoft :P