Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

434
Views
How can I properly document vue properties with type "Object" using jsDoc?

What I am trying to achieve is to document properties that have the type "Object" e.g.

props: {
    foo: {
        type: Object,
        required: true
    }
}

Now this object foo can and will have multiple entries from which some are mandatory while others will be optional. e.g.

<my-component 
   :foo="{
        mandatoryItem1: 'bar',
        mandatoryItem2: {
            mayBeEvenNested: true
        },
        optionalItem1: 'baz',
        ...
    }"
/>

Problem is that when using the property you would have to check the source code of the component to know which entries have to be present in the property. While using typescript too eliminate this problem would be great, we can not switch to TS right now, so we have to use jsDoc instead. And we would like to do it the proper way.

When documenting functions and its parameters you can describe a nested parameter object like this (or something like that):

/**
 * @param bar {Object} object containg...
 * @param bar.mandatoryItem1 {String} ...
 * @param bar.mandatoryItem2 {Object} ...
 * @param bar.mandatoryItem2.mayBeEvenNested {Boolean} ...
 */
function foo(bar) {

}

How can I do the same or anything like this for a vue property?

Ideally we would like to use something like vue-styleguidist in the future so automatically generate the docs for our components using the jsDoc so it is important to use the "right" syntax.

PS: We would like to to the same for properties with type "Array" i.e. describing how the objects in the array would look like.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You should have something like this:

/**
 * @typedef {Object} Bar
 * @param {String} mandatoryItem1
 * @param {OtherObj} mandatoryItem2
 */

export default {
  name: 'my-component',
  props: {
    /** @type {Bar} */
    foo: { type: Object, required: true }
  }
}

where OtherObj is another type definition.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!