Sequelize.js JSDoc如何在不创建新的typedef的情况下向type添加成员

Sequelize.js JSDoc如何在不创建新的typedef的情况下向type添加成员,sequelize.js,jsdoc,Sequelize.js,Jsdoc,据说我有一种叫做a和B的类型 /** * @typedef A * @type {object} * @property {String} id this is id A * @property {String} name this is name A * @property {String} child_id this is id B */ /** * @typedef B * @type {object} * @property {String} id this is

据说我有一种叫做a和B的类型

/** 
 * @typedef A
 * @type {object}
 * @property {String} id this is id A
 * @property {String} name this is name A
 * @property {String} child_id this is id B
 */

/** 
 * @typedef B
 * @type {object}
 * @property {String} id this is id A
 * @property {Number} qty this is qty B
 */
还有什么我可以吃的吗

{
   id:"a",
   name:"a",
   B:{
     id: "b",
     qty:0
   }
}
不重写typedef


我有一个返回Sequelize对象的函数,这就是为什么从我对你的问题的理解来看,考虑到你提供的预期输出对象,你可以通过修改
a
的typedef来解决这个问题

/** 
 * @typedef A
 * @type {object}
 * @property {String} id this is id A
 * @property {String} name this is name A
 * @property {B} type B
 */

/** 
 * @typedef B
 * @type {object}
 * @property {String} id 
 * @property {Number} qty 
 */
除非您需要一个特定引用子
B
对象id的字段?由于某种原因,您不希望显式定义子
B
关系。在这种情况下,您可以执行此操作并将
B
指定为可选

/** 
 * @typedef A
 * @type {object}
 * @property {String} id this is id A
 * @property {String} name this is name A
 * @property {String} idOfB - A string that holds the id from B
 * @property {B} [B] - Notice the square brackets, this makes it an optional property.
 */
下面是VSCode提供类型帮助时生成的JSDoc的样子


最后,我做的是使用&keyword进行相交

/** 
 * @typedef A
 * @type {object}
 * @property {String} id this is id A
 * @property {String} name this is name A
 * @property {String} child_id this is id B
 */

/** 
 * @typedef B
 * @type {object}
 * @property {String} id this is id A
 * @property {Number} qty this is qty B
 */
我可以用我的定义说

@returns {A & { B : B }} 
或者创建新的typedef

/** 
 * @typedef C
 * @type {object}
 * @property {A & {B:B}} B inside A relation
 */

哦,这个主意不错。但实际上我想写的是,它将返回B,而不是可选的扩展typedef是首选的,因为我太傻了,没有注意到github上出现了同样的问题