应该是我叫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的样子
最后我所做的是使用&关键字相交
/**
* @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
*/