How can I limit JSDoc options based on another value?

41 views Asked by At

I've thought of another option now that I've asked this one: create typedefs and use those with the | operator. Likely will end up being what I do.

I've got an array of objects. Those objects follow this structure (there are other properties but they don't matter here):

{ type: 'string' }

I want to add another property, with different possible values based on what the value of type is. The new object would be as follows:

{ type: 'string', subtype: 'string' }

I know how I can give a list of possible options. I can use ('blah'|'blippity'|'hooplah') in my JSDoc comment. However, I have no clue how to make that list of options depend on the first value. Each type should have a different list of subtypes.

In my situation, I need type to be either 'button', 'slider', or 'spacer'. Buttons should be able to have the subtype 'text' or 'icon', sliders should have 'smooth' or 'stepped', and spacers should have 'major' or 'minor'.

I'm using this for VSCode's Intellisense, so if there's something that can do that isn't in the JSDoc standard, that works fine too. If this isn't possible with the existing tools, that's fine- I sort of expect this functionality not to exist as this is nearing standalone program functionality. I couldn't find anything like this question elsewhere, but please do link me if you know of anywhere else this has been answered.

0

There are 0 answers