在我的 VS2015 JavaScript 应用程序中,我有一个从 REST API 获得的 JSON 对象,我使用 JSDoc@typedef
注释记录了该对象:
/**
* @typedef {Object} JSON_Response
* @property {Number} id
* @property {String} name
* @property {JSON_Response_Tag} tag
*/
/**
* @typedef {Object} JSON_Response_Tag
* @property {Number} id
* @property {String} color
*/
当我在使用这些 JSON 对象的方法的 JSDoc 注释中引用此类型时,我可以很好地获得 Intellisense 文档:
/**
* @param {JSON_Response} response
*/
function process_response(response) {
// process response here...
}
但是,我根本无法让它与数组一起使用 - 当我尝试索引数组时,我会得到“黄色三角形”菜单,当 VS 无法为您获取 Intellisense 上下文时会发生这种情况:
/**
* @typedef {Object} JSON_Response
* @property {Number} id
* @property {String} name
* @property {JSON_Response_Tag[]} tags
*/
/**
* @param {JSON_Response} response
*/
function process_response(response) {
response.tags[0]. // no intellisense here
}
JSDoc 的其他推荐方法 using{Array.<JSON_Response>}
通知 VS 这response
是一个数组,但不提供 Intellisense 下的任何内容。Microsoft 自己的 XML 注释确实提供了这种功能,但仅限于函数参数 - 我无法进入对象内部,我也不想这样做,因为每次调用函数时我都必须添加此文档。
有没有办法在 JavaScript 的 VS Intellisense 中记录数组及其底层类型?
如果我必须编写代码,我想尽量减少副作用/能够将其排除在发布之外。