How can you use type as a number in JSDOC?

  • 0
    There is a banal function using JSDOC, and you can insert the test argument value value1, value2 into it, others will be like errors. Is it possible to use a number instead of a string?
    Here is an example with string that will work
    /**
     * @param {'value1', 'value2'} test
     */
    function example(test){}
    
    example('value1');


    But this will not be correct, but how to use the numbers differently?
    /**
     * @param {1, 2} test
     */
    function example(test){}
    
    example(1);
    JavaScript Jackson Solomon, Jul 3, 2020

  • 2 Answers
  • 0
    @param {(1 | 2)} test
    Anonymous

  • 0
    /**
    * @param {1|2} param
    */
    function temp(param) {}


    or

    /**
    * @typedef {1|2} MyType
    */

    /**
    * @param {MyType} param
    */
    function temp(param) {}
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!