-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set the def attribute, the props received by the component are still the default type #284
Comments
@bosens-China I think this behavior is related to Vue boolean casting. In your case, the |
But when I show it in the following way, it's OK modelValue: {
type: Boolean,
default: undefined
} to {modelValue: undefined, disabled: false} |
I see. In Vue, boolean props and nullable are always a gray area. At the moment You can, anyway, create a custom validator to fit your case: import { bool, fromType } from 'vue-types';
const boolWithUndefined = () =>
fromType('boolWithUndefined', bool, {
default: undefined,
});
export const switchProps = () => {
return {
modelValue: boolWithUndefined(),
// ...
};
}; |
😭 |
I took another look at the source code. It is probably an edge case related to the boolean type, so I think I could allow explicitly setting the default to |
After further investigation, I think this is a breaking change. I will keep the issue open and see if other users think this feature is useful (cc @victorgarciaesgi). For the moment, the suggestion is to use a custom validator. |
Found the same problem, I think it is still necessary, whether it is possible to determine the behavior of import { config } from 'vue-types'
config.mandatory = true; |
Hi, I plan to release this change with version 5. At the moment I published it as a beta version: let me know if it works as expected. |
test later,But can other types be forced to specify export const switchProps = () => {
return {
one: number().def(undefined),
two: bool().def(undefined),
three: string().def(undefined),
// ... other
};
}; |
If I understand correctly, boolean prop types are the only one where the value is casted if a default property is not defined. In all other cases, if the prop does not have a default property, the prop value is anyway I think that the validators (used as named imports) does not force any sensible default, so assigned props should have a Maybe I don't understand your use case. Could you provide an example with a couple of components? |
You're right |
<script >
import { defineComponent } from "vue";
import { number, string, object, array, func, bool } from "vue-types";
export default defineComponent({
props: {
test1: number().def(undefined),
test2: string().def(undefined),
test3: object().def(undefined),
test4: array().def(undefined),
test5: func().def(undefined),
test6: bool().def(undefined),
},
setup(props) {
console.log(props);
return () => 123;
},
});
</script>
test1: undefined
test2: undefined
test3: undefined
test4: undefined
test5: undefined
test6: undefined |
output
expect
The text was updated successfully, but these errors were encountered: