Comments (3)
Yep, more meaningful warnings would be helpful. Opened #13 about it.
Digging in the source, relevant lines about prop validation are here. As far as I can see, default values are used just when prop value is undefined
.
To achieve what you're looking for you could use both props and computed:
{
props: {
item: VueTypes.shape({ ... })
},
computed: {
mergedItem() {
return Object.assign({
theme: '#E58005'
}, this.item)
}
}
}
from vue-types.
Hi,
under the hood the shape
type sets a prop validation object like:
{
type: Object,
validator() {
// a custom validator that checks the prop value against the shape
}
}
The only way to get a default shape is to use the .shape().def()
method, but in that case the default shape will just be used when the prop is missing instead of beeing merged with the partial object.
Anyway this behavior matches the Vuejs docs. What's misleading is that the user can invoke .def()
without any warning from the library (that's my fault) 😅 .
Looking at vue's source I believe there's no way to get the behavior you're expecting.
from vue-types.
yeah I see what you mean, that would be really powerful though: super useful.
feel free to close the ticket if there's no way to achieve that or at least the warning would be nice :)
speaking about warnings, maybe you prefer a separate ticket, but warning for type checks are not super straight forward in my opinion: what is missing for me is the actual key name.
if i add a prop 'foo' with type string, the console will only complain about a number being passed instead of a string but doesn't specify which key. it's very hard to debug.
Thanks for your time.
from vue-types.
Related Issues (20)
- Dependency Dashboard
- custom validation does not run inside shape HOT 5
- eslint vue/require-default-prop warning HOT 8
- using `.def()` with `oneOfType` throws error HOT 3
- isRequired has unexpected behaviour with func HOT 2
- Question:Use defineProps has ESLint Error HOT 2
- Add `null` in possible generic types of `object` HOT 6
- Validator not works HOT 2
- Migrate to vitest HOT 1
- validateType throw an error when used with shape HOT 2
- Set the def attribute, the props received by the component are still the default type HOT 12
- Wrong documentation for number prop default HOT 2
- `validateType` not working with shim..? HOT 4
- `validateType(String, undefined) === true`? HOT 6
- validateType does not treat `null` the same as Vue does HOT 2
- func cannot recognize async functions for validation. HOT 2
- validate can't determine param type HOT 2
- Could not find a declaration file for module 'vue-types' HOT 6
- How to update VueTypes.extend? HOT 2
- Hello, why does undefineProps return unknown when defined? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-types.