0

In typescript I can document a dictionary/map that has certain given entries but is still a dictionary/map (as you can add or remove entries) like this

type Foo = {
    bar: number;
    moo: number;
    [key: string]: number;
};

Is there a JSDoc equivalent?

gman
  • 100,619
  • 31
  • 269
  • 393

2 Answers2

0

You can use this syntax for params

/**
 * @param {Object.<string, number>} foo
 */

I'm not sure about using the same with @typedef, but guess this one should work too:

/**
 * @typedef {Object.<string, number>} Foo
 */

Type docs http://usejsdoc.org/tags-type.html

Lesha Ogonkov
  • 1,218
  • 8
  • 20
0

Pure JsDoc

/**
* @typedef {{bar: number, moo: number} & Object.<string, number>} Foo
*/

JsDoc with TypeScript syntax (https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures)

/**
* @typedef {{ bar: number, moo:number, [key: string]: number }} Foo
*/