如何使用 JSDoc 记录带有破折号的字段

How to document field with dash with JSDoc

给定一个不允许我修改的对象定义:

let a = {"a-b" : 5};

如何在其上添加 JSDoc?

我试过了

/**
* @type {{"a-b": number}}
*/

但是 WebStorm 告诉我这不是有效的 JSDoc。

目前这是一个尚未解决的话题,仍然是 in-progress。

我建议使用 class 评论:

/**
 * @typedef {Object}
 * @property {number} a-b
 */

这是用特殊字符记录名称路径的有效方法 - 请参阅 http://usejsdoc.org/about-namepaths.html, Namepaths of objects with special characters in the name. But WebStorm doesn't yet support it - see WEB-18032