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

159
Views
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
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!