question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

template props intellisense respect to jsdoc type

See original GitHub issue
  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: win7 x64
  • Vetur version: 0.21.0
  • VS Code version: 1.35.1

Problem

image Props intelliSense has been provided to template interpolation since #1083 , however for Object type seems not enough, is that possible to provide intelliSence type base on jsDoc @type? For the code in image, when I type . after sum, there’s no intelliSence at all, I shall expect to select from v1 and v2.

Reproducible Case

Create a Vue component with following code

// Test.vue
<template>
  <div class="container">
    <p v-if="loading">loading...{{sum}}</p>
    <h1 v-if="!loading">
      <p>{{sum.v1}}</p> <!--  <--- here after sum I shall have intelliSense -->
      <p>{{sum.v2}}</p>
    </h1>
  </div>
</template>

<script>
export default {
  name: 'Test',
  props: {
    loading: {
      type: Boolean,
      required: true
    },
    /** @type {{v1: number, v2: number}} */
    sum: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      message: 'Using Parcel In A Vue.js App',
    };
  },
};
</script>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
azuryuscommented, Jun 17, 2019

You can declare your props’ types like this:

export default {
  props: {
    /** @type {import('vue').PropOptions<{v1: number, v2: number}>} */
    sum: {
      type: Object,
      required: true
    }
  }
}

I don’t know if it’s the recommended way, but it will enable IntelliSense with your object’s properties.

3reactions
yoyo930021commented, Aug 1, 2020

If you use typescript:

import { PropType } from 'vue'

export default {
  props: {
    sum: {
      type: Object as PropType<{v1: number, v2: number}>,
      required: true
    }
  }
}

javascript:

export default {
  props: {
    sum: {
      /** @type {import('vue').PropType<{v1: number, v2: number}>} */
      type: Object,
      required: true
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using JSDoc to enable intellisense for render props in vscode
Setup. We have a react codebase where we have many React components with the render props pattern. In this codebase we haven't enabled ......
Read more >
How to use JsDoc annotations with VsCode for intellisense
Here, we are using @typedef to define custom type definations, in this case type Moment which is provided in the "moment" library and...
Read more >
Documenting components - Vue Styleguidist
Vue styleguidist will display the contents of your components' JSDoc ... You can use the following tags when documenting components, props and methods....
Read more >
Two ways you can take advantage of types in JavaScript ...
Here's an example of declaring a variable and assigning it a value. The intellisense is coherent with the type of that value:.
Read more >
how to document this keyword in custom components with ...
The this keyword in Vue framework is an object of type Vue . You can identify it by debugging your code within your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found