Yup: stripUnknown doesn't work in strict mode

Created on 23 Oct 2019  路  2Comments  路  Source: jquense/yup

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?

Most helpful comment

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.

All 2 comments

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?

Was this page helpful?
0 / 5 - 0 ratings