jsdoc

JSDoc: Return object structure

删除回忆录丶 提交于 2019-11-29 18:58:32
How can I tell JSDoc about the structure of an object that is returned. I have found the @return {{field1: type, field2: type, ...}} description syntax and tried it: /** * Returns a coordinate from a given mouse or touch event * @param {TouchEvent|MouseEvent|jQuery.Event} e * A valid mouse or touch event or a jQuery event wrapping such an * event. * @param {string} [type="page"] * A string representing the type of location that should be * returned. Can be either "page", "client" or "screen". * @return {{x: Number, y: Number}} * The location of the event */ var getEventLocation = function(e,

How to document resolved values of JavaScript promises

余生颓废 提交于 2019-11-29 18:46:52
问题 Given this code : function asyncFoo() { return new Promise(function (fulfill, reject) { doAsyncStuff(function(err, data) { if(err) reject(new Error(err)); else fulfill(new Bar(data)); }); }); } How can I document that asyncFoo will return a Promise that, when fulfilled will yield an instance of Bar , and when rejected will yield an instance of Error ? /** * @return << Here, what do I have to write? >> */ function asyncFoo() { ... } 回答1: Looks like you should do the following, based on some

How to document callbacks using JSDoc?

微笑、不失礼 提交于 2019-11-29 16:08:49
问题 Given a Javascript function that takes callback functions as parameters: var myFunction = function(onSuccess, onFailure) {...} How do I document onSuccess 's return type and arguments? 回答1: In JSDoc 3.1 and later, you can use the new @callback tag to describe the callback function in a separate comment block. You can then refer to the callback in the docs for your method. Here's an example: /** @class */ function MyClass() {} /** * Do something. * @param {MyClass~onSuccess} cb - Called on

How do you document JSDoc with mixed parameter type?

纵饮孤独 提交于 2019-11-29 16:08:17
问题 How do I document a method in JavaScript using JSDoc when the parameter type can be mixed? I have method on a Dialog object where I can show HTML or my own Viewable objects. The method JSDoc looks like this: /** * Can pass in viewable object, or some HTML element * * @param viewable viewable {Viewable} or HTML element {HTMLElement} or String {string} * @param {Boolean} cancelable is cancellable * @param title string or data object of String and Id {Title:String, Id:String} for setting HTML id

How do I document AMD + Backbone project with JSDoc3

痴心易碎 提交于 2019-11-29 10:27:30
I have a Backbone boilerplate based project, that I want to document with recent jdoc-toolkit Though I can't get it to generate anything but empty _global class Code sample: /** * This is a root model for DLClass * @module models/DLClass */ define([ 'underscore', 'backbone' ], /** @lends DLClass */ function (_, Backbone) { /** * This is a root model for DLClass * @class DLClass * @constructor * @return Session Object */ var DLModel = Backbone.Model.extend({ /** @lends DLClass.prototype */ /** * Generic tap event * @param touchEvent */ onTap: function (touchEvent) { }, Try adding the @namespace

Document generic type parameters in JSDOC

二次信任 提交于 2019-11-29 09:23:13
In JSDoc there exists the possibility to document the exact types of array contents like this : /** @param {Array.<MyClass>} myClasses An array of MyClass objects. */ TestClass.protoype.someMethod = function( myClasses ){ myClasses[0].aMethodOnMyClass(); } This makes code completion in IDEs like WebStorm actually provide the right type information after the [0]. . This works well for the Array type, however I have my own collection types where I would like to make use of this feature, too. The problem is I cannot find the right syntax (maybe because there is none, yet). I would love to be able

How to extend a typedef parameter in JSDOC?

梦想与她 提交于 2019-11-29 06:45:14
问题 Assuming you have the following code inside a ES6 class (documentation): /** * @typedef Test~options * @type {object.<string>} * @property {array} elements - An array containing elements * @property {number} length - The array length */ /** * @param {Test~options} opt - Option object */ test(opt){ } Now I would like to document another function, let's name it test2 . This function takes exactly the same options object, but needs another property parent . How to document this without

Mixing JavaScript and TypeScript in Node.js

前提是你 提交于 2019-11-29 02:28:37
问题 While having parts of a Node.js in plain ES6, is it possible to mix in some Typescript modules within the same project? E.g. having some Types defined in TypeScript that are imported via require into plain ES6 files? 回答1: Yes this is possible. Combine the following compiler flags --allowJs Explicitly supports mixed JavaScript and TypeScript sources --outDir Since all files will be transpiled, it is necessary to output the resulting JavaScript into a different directory otherwise the input .js

JSDoc: How do I document the “options” object literal for a parent “class”? [duplicate]

偶尔善良 提交于 2019-11-29 02:07:07
问题 This question already has answers here : How to describe “object” arguments in jsdoc? (5 answers) Closed 3 years ago . I am using jQuery's $.widget() base "class" which provides an option() method. Since the method is not in my code, I don't have a place to document the argument. I tried to put jsDoc on the fields in the default options literal, but they're simply not picked up. Then I tried to use the @class and @lends tags on the same object literal, but this may be quite confusing as the

How to document a dictionary in JSDoc?

我们两清 提交于 2019-11-28 17:19:47
问题 Having next example: var CONF = { locale: { "en": { name: "English", lang: "en-US" }, "es": { name: "Spanish", lang: "es-ES" } } }; And knowing that what the locale property contains is a dictionary object, which comes from the database, how can I document its inner properties with JSDoc? Currently I am thinking to typedef type for my locale objects, then may I be able to set the locale property to simply an Array of my defined type? Is this the right way to do it? 回答1: According to the JSDoc