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.
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:
- Created 2 years ago
- Reactions:6
- Comments:9 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please set
"vetur.validation.templateProps": false
when you don’t need it.Another information: https://github.com/vuejs/vetur/issues/2235#issuecomment-688013007
https://vuejs.github.io/vetur/guide/interpolation.html#prop-validation
https://github.com/vuejs/vetur/issues/2141#issuecomment-674117099
It is by design.