JSDoc to describe object with dynamic properties

Viewed 636

I looked at How to document an array of objects in JSDOC however I have a slightly different problem:

{
    1232345345: 'hello',
    1454765456: 'hello'
}

my object will contain properties that are timestamps.

What would be the best way of writing this in JSDoc? I came up with the following, but is this correct and valid JSDoc?

/**
 * @typedef {{[timestamp: number]: string}} Things
 */
1 Answers

Based on JSdoc's tags-type documentation (look at the section on Arrays and objects (type applications and record types), you can define a type as an Object with number keys and string values:

/**
 * @type {Object.<number, string>}
 */
const x = {
  1232345345: 'hello',
  1454765456: 'hello'
}
Related