[IMP] props validation: cannot set default value on mandatory props

This commit is contained in:
Géry Debongnie
2022-02-04 09:36:54 +01:00
committed by Aaron Bohy
parent 24ce8613c5
commit 1fb1d37e32
5 changed files with 63 additions and 8 deletions
+6 -1
View File
@@ -168,11 +168,15 @@ For each key, a `prop` definition is either a boolean, a constructor, a list of
- `shape`: if the type was `Object`, then the `shape` key describes the interface of the object. If it is not set, then we only validate the object, not its elements,
- `validate`: this is a function which should return a boolean to determine if
the value is valid or not. Useful for custom validation logic.
- `optional`: if true, the prop is not mandatory
There is a special `*` prop that means that additional prop are allowed. This is
sometimes useful for generic components that will propagate some or all their
props to their child components.
Note that default values cannot be defined for a mandatory props. Doing so will
result in a prop validation error.
Examples:
```js
@@ -190,7 +194,8 @@ class ComponentB extends owl.Component {
element: {type: Object, shape: {id: Boolean, text: String }
},
date: Date,
combinedVal: [Number, Boolean]
combinedVal: [Number, Boolean],
optionalProp: { type: Number, optional: true }
};
...