Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.4K
Views
JSDoc: estructura del objeto de retorno

¿Cómo puedo decirle a JSDoc sobre la estructura de un objeto que se devuelve? Encontré la sintaxis de @return {{field1: type, field2: type, ...}} description y la probé:

 /** * 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, type) { ... return {x: xLocation, y: yLocation}; }

Si bien esto se analiza con éxito, la documentación resultante simplemente establece:

 Returns: The location of an event Type: Object

Estoy desarrollando una API y necesito que las personas sepan sobre el objeto que se les devolverá. ¿Es esto posible en JSDoc? Estoy usando JSDoc3.3.0-beta1.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Defina su estructura por separado usando un @typdef :

 /** * @typedef {Object} Point * @property {number} x - The X Coordinate * @property {number} y - The Y Coordinate */

Y utilícelo como el tipo de retorno:

 /** * 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 {Point} * The location of the event */ var getEventLocation = function(e, type) { ... return {x: xLocation, y: yLocation}; }
over 4 years ago · Santiago Trujillo Report

0

Una alternativa a las sugerencias ya publicadas, puede utilizar este formato:

 /** * Get the connection state. * * @returns {Object} connection The connection state. * @returns {boolean} connection.isConnected Whether the authenticated user is currently connected. * @returns {boolean} connection.isPending Whether the authenticated user's connection is currently pending. * @returns {Object} connection.error The error object if an error occurred. * @returns {string} connection.error.message The error message. * @returns {string} connection.error.stack The stack trace of the error. */ getConnection () { return { isConnected: true, isPending: false, error } }

que dará el siguiente resultado de documentación:

 Get the connection state. getConnection(): Object Returns Object: connection The connection state. boolean: connection.isConnected Whether the authenticated user is currently connected. boolean: connection.isPending Whether the authenticated users connection is currently pending. Object: connection.error The error object if an error occurred. string: connection.error.message The error message. string: connection.error.stack The stack trace of the error.
over 4 years ago · Santiago Trujillo Report

0

Una solución limpia es escribir una clase y devolverla.

 /** * @class Point * @type {Object} * @property {number} x The X-coordinate. * @property {number} y The Y-coordinate. */ function Point(x, y) { return { x: x, y: y }; } /** * @returns {Point} The location of the event. */ var getEventLocation = function(e, type) { ... return new Point(x, y); };
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!