Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
How to write a parameter type of prototype in JSDoc and TypeScript?

I'm trying to write some helper functions for a library that will make it easier to use some Object functions. Here is some sample code of what I mean:

// ./utc-value.js
const makeEnumerable = require('./make-enumerable');

/* Data class to represent UTC values to be handled by an ExtendedDate class
 *   const dt = new Date();
 *   const xdt = new ExtendedDate(dt); 
 *   xdt.utc === new UtcValue(dt); // true
 *   xdt.date === dt.getDate(); // true
 *   xdt.utc.date === dt.getUTCDate(); // true
 */
class UtcValue {
  constructor(dt) {
    this._dt = dt;
    Object.defineProperty(this, '_dt', { enumerable: false, value: dt } );
  }

  get date() {
    return this._dt.getUTCDate();
  }
  ...
}

makeEnumerable(UtcValue.prototype, 'date');
module.exports = UtcValue;

While the makeEnumerable function looks like this:

/**
  * Maps enumerable=true across all named properties
  * @param prototype
  * @param {string} properties
  */
function makeEnumerable(prototype, ...properties) {
  const propertyDescriptors = Object.getOwnPropertyDescriptors(prototype);
  
  for(const property of properties) {
    const attributes = propertyDescriptors[property] || {};
    attributes.enumerable = true;
    Object.defineProperty(prototype, property, attributes);
  }
}

module.exports = makeEnumerable;

What should the JSDoc signature of makeEnumerable look like, to indicate to a user that I'm expecting a prototype, such as Object.prototype or obj.constructor.prototype? I'm also writing the ./make-enumerable.d.ts file manually (project is JavaScript classic with plans to move to TypeScript in a future version), so the proper way to document the signature would be appreciated.

// ./make-enumerable.d.ts
export default function makeEnumerable(
  prototype: typeof Object.prototype, 
  ...properties: string[]): void;
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda