Javascript is required
·
1 min read

Vue Tip: Document Your Component Props Using JSDoc

Vue Tip: Document Your Component Props Using JSDoc Image

It can be useful to document your component props so that they show up when you hover over the component in your IDE. You can do this using JSDoc in the TypeScript interface that you pass to the defineProps function:

MyComponent.vue
1<script setup lang="ts">
2export interface Props {
3  /** The name of the user. */
4  name: string
5  /** The age of the user. */
6  age: number
7}
8defineProps<Props>()
9</script>

It's also possible to document the props in the defineProps function:

MyComponent.vue
1<script setup lang="ts">
2defineProps<{
3  /** The name of the user. */
4  name: string
5  /** The age of the user. */
6  age: number
7}>()
8</script>

If you hover over the prop name in your IDE, you should see the documentation:

Screenshot of the prop documentation in VS Code

If you liked this Vue tip, follow me on X to get notified about new tips, blog posts, and more. Alternatively (or additionally), you can subscribe to my weekly Vue & Nuxt newsletter:

I will never share any of your personal data. You can unsubscribe at any time.