What is the correct JSDoc syntax for a local variable?

后端 未结 4 1375
面向向阳花
面向向阳花 2021-02-18 15:10

For a function like this...

function example() {
  var X = 100;

  ...

  var Y = \'abc\';

  ...

  return Z;
}

I need to explain the purpose

相关标签:
4条回答
  • 2021-02-18 15:48

    one liner:

      /** @type {string} */
      var Y = 'abc';
    
    0 讨论(0)
  • 2021-02-18 15:49

    It seems that JS Docs ignores comments within the "block" (E.g. class, function, etc.). I tried...

    @description
    @inner
    @instance
    @member
    @memberof
    @name
    @summary
    

    ...and others. I was unable to get any of them to generate documentation. Throughout the JS Doc examples they use normal JS comments for this sort of thing.

    I have concluded that there is no official JS Doc syntax for this.

    0 讨论(0)
  • 2021-02-18 15:54

    I usually use something like the code below in my projects.

    function example() {
      /**
       * Need to explain the purpose of X here.
       * @type {number}
       */
      var X = 100;
    
      ...
    
      /**
       * Need to explain the purpose of Y here.
       * @type {string}
       */
      var Y = 'abc';
    
      ...
    
      return Z;
    }
    
    0 讨论(0)
  • 2021-02-18 16:01

    Best thing that worked for me:

    /**
      * @name AssetAutoGenerationOption
      * @type {"all" | "master" | "off"}
      */
    export type AssetAutoGenerationOption = "all" | "master" | "off";
    
    0 讨论(0)
提交回复
热议问题