What is the best way to specify multiple types as a repeatable parameter?

/**
 * Calculate the total sum of all numbers provided to the function.
 * @example
 * sum([1,2,3])
 * //results in 6
 * sum(1,2,3)
 * //results in 6
 * @param {number[]|...number} params - Represents an array of numbers or individual numbers passed as arguments
 */
function sum(params) {
    var args = params instanceof Array ? params : arguments;
    for (var i = 0, sum = 0; i < args.length; i++)
        sum += args[i];
    return sum;
}

'params' may be an array or a series of individual numbers

However, specifying "@param {number[]|...number}" does not work.

The defined documentation output is identical to "@param {number[]|number}"

What would be the most appropriate way to clarify this situation?

Answer №1

The key is to utilize parentheses. I implemented the following and it functions properly.

* @param {...(object|string)} col - A selection of columns that can be optionally chosen.

When tailored to your parameter names, this might be effective:

* @param {...(number[]|number)} params - ???

I could not locate any official documentation on the use of parentheses, but it seems to work under JSDoc 3.4.2.

This explanation:

/**
 * Manually choose specific columns.
 * @param {...(object|string)} col - An optional set of columns to select.
 * Each argument can either represent a fully-qualified column name in the format
 * &lt;table-alias&gt;.&lt;column-name&gt;, or an object with the characteristics described below. If no columns are specified, all columns will be selected.
 * @param {string} col.column - The fully-qualified column name.
 * @param {string} col.mapTo - The property name in which the column should be stored within the resulting normalized object. 
 * @param {function} col.convert - A function for converting a single value retrieved from the database. For instance, converting a bit value into a boolean.
 * @return {this}
 */

Results in this document:

https://i.sstatic.net/Sp7j0.png

I hope this information is helpful!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Embedding images using a blob or base64 format does not function properly on iOS devices

I'm facing an issue with setting the src of an img tag to display an image. The code snippet below works fine on android, mac, and windows, but it is not functioning correctly on iOS: let base64Image = pageModel.image; this.$currentPageImage.src = `da ...

Attempting to create a conditional state in Redux based on data fetched from an API

I'm currently exploring the most effective way to set up a conditional modal popup based on whether the response from an API call is null or not. While I typically work with functional components, the component I'm working with here is built as a ...

Deleting a key from one object will also remove that key from another object - JavaScript

I have come across an interesting issue with my Javascript code. I am working with two objects, dict1 and dict2, where I need to maintain a form of state and then post the final object. When I click on certain buttons, I assign dict1 to dict2. However, wh ...

What steps do I need to take to ensure that when running npm start, Chrome opens in incognito mode or that caching is

During my development process, I have encountered frustrating issues related to caching that are difficult to debug. I am looking for a way to disable caching in order to alleviate this problem. One approach I am considering is modifying the default beha ...

Encountering an issue when trying to run npm run dev-server on Windows 10

Having trouble running the dev-server for superset-frontend. Encountering this error message. Any assistance would be greatly valued.https://i.stack.imgur.com/zsVU4.png ...

Eliminating single and multiple relationships - Mongoose

My Assignment schema includes references to both Groups and Projects. Assignment == Group [One-One Relationship] Assignment == Projects [One-Many Relationship] Here is my Assignment Schema: var AssignmentSchema = new Schema({ name: String, group ...

Dynamically loading form element values

Is it feasible to retrieve dynamic values within a form using jQuery? Consider this example: <form id="contact" method="post" action"contact.php" class="ajaxForm"> <label>Name:</label> <input type="text" name="name" /> ...

Converting an HTML page into a base 64 string: Step-by-step guide

Currently, I am utilizing Angular 6 for my project. On the index page, I am binding data and then submitting it to the database. My objective is to submit the entire HTML page with the bound data as a string in the database. Is there a way to convert an H ...

Turn one square so that its center aligns with the center point of the second square

I am currently exploring how to dynamically position the big red square in the center point of the blue square using Javascript. Both squares, positioned using HTML, should be able to move dynamically. I struggle with the mathematical aspect of this task ...

working with html data in a bootstrap modal using javascript

Utilizing an id, I pass data to a bootstrap modal and link that id with stored data. $("#fruit").html($(this).data("fruit")); In addition, I am appending data to the bootstrap modal $('#mymodal').find('.modal-body').append('< ...

Using JavaScript, create a script that will automatically convert the value of an AJAX calendar to a datetime

I am struggling with converting a string into a proper date format using JavaScript in an ASP.net textbox with AJAX calendar extender control. <asp:TextBox ID="tbxReceivedDate" CssClass="selectstyle" runat="server" MaxLength="100" Width="200" onblur="p ...

What is the process for converting and transferring the date in Google Apps Script to generate a new event in Google Calendar?

To create an event in GAS, follow this link: https://developers.google.com/apps-script/reference/calendar/calendar#createEvent(String,Date,Date,Object) var event = CalendarApp.getDefaultCalendar().createEvent('Apollo 11 Landing', new Date(& ...

The issue with ng-repeat causing incorrect image width in Flexslider

My webpage features image scrolling functionality, powered by Flexslider. The images on the page are sorted by date - for example, selecting "last 7 days" will display images from the past week (data managed through AngularJS). However, when the JSON dat ...

Issues are arising post-deployment despite JavaScript being enabled in the browser, including a <noscript

Upon deployment, an error appeared in the network tab stating: We're sorry but app-frontend doesn't work properly without JavaScript enabled. Please enable it to continue. Here is the code snippet from the index.html file of a vueJS app: <bo ...

Utilizing Next.js to dynamically render a modal using data from the router's query parameters

I have an interactive feed that showcases cards. These cards trigger a modal to open, providing more details related to each card. The information is passed down two levels using props and everything functions smoothly until I incorporate Next Link for mod ...

Find all Mondays occurring within a specified date range using Moment.js

I need to extract all Mondays within a specific date range. let start = moment(this.absence.FromDate); let end = moment(this.absence.ToDate); The user has the option to deactivate certain weekdays during this period by setting booleans. monday = true; t ...

Adding a detached element under certain conditions

When attempting to add a detached span based on a specific condition, I encountered the following situation. const arrow = d3 .create('span') .classed('arrow', true) .text('\u2192'); //d3.select('bod ...

Google Bar Graphs Cannot Display Decimal Values

Having an issue with my bar chart from Google Chart not displaying float numbers. Other types of bar charts provided by Google Chart work fine, but this specific type doesn't show the float numbers. Here is the code I have written: http://jsfiddle.ne ...

What causes the variance in timestamps between JavaScript and PHP?

I am facing a discrepancy between the JavaScript and PHP timestamps I have created. There is roughly a 170-second difference between the two. 1302162686 PHP - time() 1302162517 JavaScript - Math.round(new Date().getTime() / 1000) If anyone has any insi ...

React DOM's offsetHeight prior to rendering

I am struggling to figure out how to position a React DOM element based on its offsetHeight. The issue is that I cannot determine the offsetHeight of an element that hasn't been created yet (so the height cannot be passed as a parameter to the render ...