futurGH / ts-to-jsdoc

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

Generate jsdoc for var declaration #29

Closed j3rem1e closed 1 year ago

j3rem1e commented 1 year ago

Closes #28

futurGH commented 1 year ago

Thanks for the PR! Apologies for the delay in getting to this. I'm leaning towards not introducing new JSDoc on every variable if it doesn't already have documentation of some sort, largely out of concern for codebase clutter, but I'm interested in hearing more opinions than my own.

j3rem1e commented 1 year ago

To add more context, it was part of an experiment to try to document Svelte typescript component. Svelte doesn't support natively typescript, and uses preprocessor to transpile typescript to javascript. There are tools which are able to generate a component documentation by extracting information from the jsdoc comment and annotation like @type.

For example, for this component:

<script lang="ts">
  /**
   * Component Size
   */
  export let size : 'medium'|'large';
</script>

The tools will extract a property "size" with the documentation "Component Size", but the type will be lost.

I tried to use ts-to-jsdoc to generate a type annotation in the jsdoc to fix it. It works great for function, but it doesn't work for exported properties, which is the main source of documentation for a component.

In my test, the documentation was only added for top level var, but honestly I could be wrong.

futurGH commented 1 year ago

Thanks for waiting, and for the example. I think the direction I'm going to go in is only documenting top-level variables that already have a JSDoc-style comment attached to them. So

const foo = 1:

won't get an @type tag, but

/** Foo */
const foo = 1;

will. I appreciate the contribution!