我正在尝试记录以下对象:
let x = {
stopCP: {
enabled: false,
method: "POST",
body: "STOP"
},
startCP: {
enabled: false,
method: "POST",
body: "START"
},
restartCP: {
enabled: false,
method: "POST",
body: "RESTART"
},
viewLog: {
enabled: false,
method: "POST",
body: "VIEWLOG"
}
};
如您所见,“子对象”的键都相同。当然,我可以手工记录每个属性,但是我想知道是否可以做这样的事情(也可以使用*
之类的“任何占位符”):
/**
* @typedef {Object} options
* @prop {Object} * <--- I want this to apply to stopCP, startCP, restartCP and viewLog all at once
* @prop {Boolean} *.enabled <--- This should target all "enabled" properties of the child objects
* @prop {String} *.method <--- Same for this one
* @prop {String} *.body <--- Also same
*/
另外,我将如何指定一定数量的字符串?我的意思是这样的:
/**
* @typedef {Object} options
* @prop {String} *.method ["POST" || "GET" || "PUT"] <---
*/
...这将告诉我,我只能使用POST,GET或PUT作为该属性的值。