Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

438
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda