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

Schema.node does not allow a value of 'null' #4

Open
ddeklerk opened this issue May 6, 2016 · 2 comments
Open

Schema.node does not allow a value of 'null' #4

ddeklerk opened this issue May 6, 2016 · 2 comments
Labels

Comments

@ddeklerk
Copy link

ddeklerk commented May 6, 2016

I could be missing something, but when a component does not have a child, null is passed instead. This means that a component without child will fail the propType validation when Schema.node is used.

For reference, this is the schema that I use.

Test.propTypes = propTypeSchema({
  type: 'object',
  properties: {
    children: {
      type: Schema.node,
      required: false,
    },
    route: {
      type: 'object',
    },
  },
});
@ddeklerk
Copy link
Author

ddeklerk commented May 6, 2016

First of all, it seems I was using Schema.node incorrectly. It should have been children: Schema.node.

But that still does not fix my problem. In the mean time I am using this to get around it.

Test.propTypes = propTypeSchema({
  type: 'object',
  properties: {
    children: {
      oneOf: [{ type: 'null' }, ...Schema.node.oneOf],
    },
    route: {
      type: 'object',
    },
  },
});

@charypar charypar added the bug label Jun 27, 2016
@charypar
Copy link
Contributor

@ddeklerk I think you're using Schema.node almost correctly, but the definition is missing the null case. You should be able to do

Test.propTypes = propTypeSchema({
  type: 'object',
  properties: {
    children: Schema.node,
    route: {
      type: 'object',
    },
  },
});

Marked as a bug.

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

No branches or pull requests

2 participants