const schema = yup.object().shape({
email: yup.string().email(),
name: yup.string().ensure(),
lastname: yup.string().ensure(),
});
const res = schema.validateSync({name: 'ads', foo: 'foo'}, {
strict: true,
abortEarly: false,
stripUnknown: true
});
res is the object {name: 'ads', foo: 'foo'}, that is stripUnknown doesn't work when strict specified.
At the same time, there is no overt mentioning that stripUnknown doesn't work with strict in the documentation.
It should be explicitly said in the documentation about this behavior. But I wonder why is it such? Why not to make stripUnknown work always when it is true?
What is the use case that one option should implicitly disable another option?
I was able to get around this by calling validateSync() with strict: true, stripUnknown: false, then calling it again with the result of the previous call and strict: false, stripUnknown: true.
This is still an issue in 0.29.3.
Are there any valid reasons why stripUnknown shouldn't work when validating in strict mode?
Most helpful comment
I was able to get around this by calling
validateSync()withstrict: true, stripUnknown: false, then calling it again with the result of the previous call andstrict: false, stripUnknown: true.