Skip to content
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

Add ability to ignore extraneous properties, instead of failing with error #35

Open
ronniel1 opened this issue Oct 19, 2022 · 2 comments

Comments

@ronniel1
Copy link

Hi,

I'm evaluating this package for replacing Joi validations that we have.
The main thing I like in this package is that I don't need to declare the object type and schema separately (using t.InferType).

One thing that I'm missing is the ability to to ignore extraneous properties from the returned value of t.as(). So if I get invalid properties, there will be no error, and the object returned from t.as() will not include these properties

@arcanis
Copy link
Owner

arcanis commented Oct 19, 2022

Can you share a full example of what you have and what you expect?

@ronniel1
Copy link
Author

Here is an example:

   const isData = t.isObject({
      data1: t.isOptional(t.isString()),
      data2: t.isString(),
   });

   const dynamicData = {
      data1: 'd1',
      data2: 'd2',
      data3: 'd2',
   };

   const convertedData = t.as(dynamicData, isData, { errors: true });
   console.log(convertedData.errors);
   console.log(convertedData.value);

Expected result is not error, and value to containt:

{
   data1: 'd1',
   data2: 'd2',
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants