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

ow.object.exactShape does not treat undefined values correctly #208

Open
mnmkng opened this issue Mar 30, 2021 · 1 comment
Open

ow.object.exactShape does not treat undefined values correctly #208

mnmkng opened this issue Mar 30, 2021 · 1 comment

Comments

@mnmkng
Copy link

mnmkng commented Mar 30, 2021

What happens:

const ow = require('ow').default;

ow({ foo: 'bar', bar: undefined }, ow.object.exactShape({
    foo: ow.string,
}));

Throws:

ArgumentError: Did not expect property `bar` to exist, got `undefined` in object
...
 validationErrors: Map(1) {
    'object' => Set(1) {
      'Did not expect property `bar` to exist, got `undefined` in object'
    }
  }

Expected behavior:

Even though I understand that there's a difference between those two objects:

const obj1 = {};
const obj2 = { bar: undefined };

I believe that for the purposes of argument validation they are the same and the error message "Did not expect property bar to exist, got undefined in object" does not make sense to me. I would expect the original code to not throw.

If accepted as a bug, I can do the PR to fix it. Thanks.

@atomanyih
Copy link

It does make a difference if you're spreading in your function:

const obj1 = { bar: 'foo', ...{} } // => { bar: 'foo' }
const obj2 = { bar: 'foo', ...{ bar: undefined } } // => { bar: undefined }

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