Z
Z
Zakhar Yaitskikh2020-10-30 14:40:50
JavaScript
Zakhar Yaitskikh, 2020-10-30 14:40:50

How can type be used as a number in JSDOC?

There is a banal function using JSDOC, and you can insert the argument test 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 numbers differently?
/**
 * @param {1, 2} test
 */
function example(test){}

example(1);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Anton, 2020-10-30
@Fragster

@param {(1|2)} test

A
Alexander, 2020-10-30
@Seasle

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

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

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question