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.

Prop validation treats optional props as required

See original GitHub issue
  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ
  • I have tried restarting VS Code or running Vetur: Restart VLS

Info

  • Platform: Linux
  • Vetur version: Latest
  • VS Code version: N/A (i’m using neovim, coc and coc-vetur)

Problem

When using following prop definition propName: String, vetur considers it required. But for vue it’s optional.

image

https://github.com/vuejs/vetur/blob/master/server/src/modes/script/componentInfo.ts#L371 I think problem is here. And i can try to fix it myself and make PR, if this is really a bug and not desired behaviour. For me it looks like a bug.

Reproducible Case

https://github.com/last-partizan/vetur-props-validation-bug

This is Test.vue

<template>
  <div>
    {{ foo }}
  </div>
</template>

<script>
export default {
  props: {
    foo: String,
    bar: {type: String, required: false},
  }
}
</script>

This is App.vue

<template>
  <Test />
</template>

<script>
import Test from './Test.vue'

export default {
  components: { Test },
}
</script>

This is vetur warning: <Test> misses props: foo

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
yoyo930021commented, Aug 6, 2021

Please set "vetur.validation.templateProps": false when you don’t need it.

Another information: https://github.com/vuejs/vetur/issues/2235#issuecomment-688013007

Read more comments on GitHub >

github_iconTop Results From Across the Web

Props | Vue.js
Prop Validation # · All props are optional by default, unless required: true is specified. · An absent optional prop other than Boolean...
Read more >
Vue.js prop validation for props - Stack Overflow
The feature you are looking for was provided as an optional coerce function on each component prop in Vue 1, but it was...
Read more >
How to Convert Object Props With Undefined Type to Optional ...
TypeScript was treating those properties as mandatory, even if their value is undefined . type ColumnConfig = { name: string|undefined
Read more >
React-Typescript complaining about optional props missing ...
You need ?: to flag a property as optional. Otherwise you MUST add it, even if you give it the value undefined ....
Read more >
Handling Props in Vue 3 Composition API - Level Up Coding
Props, meaning properties, are used to pass down information from one component to another usually from parent to child components in a unidirectional ......
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