0

I am trying to document the following object:

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"
    }
};

As you can see, the keys of the "child-objects" are all the same. Of course I could document every single property by hand but I was wondering if I could do something like this (aka use some kind of "any-placeholder" like a *):

/**
 * @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
 */





Also, how would I specify a set amount of strings? I mean something like this:

/**
 * @typedef {Object} options
 * @prop {String} *.method ["POST" || "GET" || "PUT"]      <---
 */

... which would tell me I can only use POST, GET or PUT as the value of that property.

Sv443
  • 708
  • 1
  • 7
  • 27
  • Possible duplicate of [How to describe "object" arguments in jsdoc?](https://stackoverflow.com/questions/6460604/how-to-describe-object-arguments-in-jsdoc) – Heretic Monkey Jan 29 '19 at 13:42
  • 1
    For the other question in your question (please refrain from asking multiple questions in a question in the future), see [How to document a string type in jsdoc with limited possible values](https://stackoverflow.com/q/19093935/215552) – Heretic Monkey Jan 29 '19 at 13:43
  • @HereticMonkey sorry, I just thought they fit well enough together. Also I tried the solution you gave but that sadly didn't work at all. – Sv443 Jan 29 '19 at 14:43
  • What do you mean it "didn't work at all"? The accepted answer has a link to the JSDoc documentation, showing how it works. How are you testing it? Please [edit] your question to include a reference to the duplicate, how you tried to implement the answer(s), and how you're determining whether the solution works or not. – Heretic Monkey Jan 29 '19 at 14:59
  • Nevermind, I was just mistyping something. [This](https://stackoverflow.com/a/34744819/8602926) ended up working perfectly for me. – Sv443 Jan 29 '19 at 15:51

0 Answers0