Skip to content

Optional and required values in PropTypes.shape #5916

@silvenon

Description

@silvenon

Not sure if there's already a good way to do this, but it would be nice to be able to do this:

PropTypes.shape({
  foo: PropTypes.string.isRequired,
  bar: PropTypes.number,
  baz: PropTypes.bool.isRequired
});

instead of having to do this:

PropTypes.oneOfType([
  PropTypes.shape({
    foo: PropTypes.string,
    bar: PropTypes.number,
    baz: PropTypes.bool
  }),
  PropTypes.shape({
    foo: PropTypes.string,
    baz: PropTypes.bool
  })
]);

The latter can get quite big if there are multiple optional values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions