6

It is common in JavaScript to work with arrays that are essentially argument lists: a small fixed length, and known types for each position. This is especially true for ECMAScript 6, which introduced features like the rest operator, spread operator and iterator protocol.

I'd like to document a function that returns an iterator object, for iterating over key/value pairs. Ideally, I'd like to be specific in its type. Is it possible to do this with (any) JSDoc? Here's my latest attempt, but I don't know if it's valid:

/**
 * @returns { { next: function(): {done: boolean, value: [string, *]} } }
 */

jsdoc-to-markdown complains about the syntax, but this might be on their end, not JSDoc 3. If so, I'll send them a bug report later.

Edit: Here is an example object that might be returned:

{
    next: function () {
        return {
            done: false,
            value: ['answer', 42]
        };
    }
}
Lloyd
  • 8,204
  • 2
  • 38
  • 53
mhelvens
  • 4,225
  • 4
  • 31
  • 55

0 Answers0