JSDoc create object with some defined and some undefined properties (Typescript [key: string]: any;)

624 Views Asked by At

I am trying to convert the following interface to JSDoc

export interface Payload {
    [key: string]: any;
    level?: string;
    code?: number;
}

so by conversion, it looks like

/**
 * @typedef Payload
 * @type {Object}
 * @property {string} [level]
 * @property {number} [code]
 */

But how do I add the option to also add any field there? How to convert [key: string]: any;?

1

There are 1 best solutions below

0
lepsch On

Declare it like the following snippet. It's the same syntax as in Typescript.

/**
 * @typedef {{
 *   [key: string]: any;
 *   level?: string;
 *   code?: number;
 * }} Payload
 */