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 React.PropTypes.any #842

Closed
Twisol opened this issue Jan 8, 2014 · 4 comments
Closed

Add React.PropTypes.any #842

Twisol opened this issue Jan 8, 2014 · 4 comments
Assignees

Comments

@Twisol
Copy link

Twisol commented Jan 8, 2014

React.PropTypes.any should allow any value to be passed as a prop. Having it as a valid PropType would allow for React.PropTypes.any.isRequired, to enforce that something is passed, whatever it may be. It also supports documenting all possible props for a component: even if a prop may be anything, having it explicitly listed as React.PropType.any is useful documentation.

@syranide
Copy link
Contributor

syranide commented Jan 8, 2014

👍

Side-question, would it be interesting to be able to specify something like anyOf(['string','object']) too (call it whatever you want), or is too much? I guess the existing implementations of oneOf, etc could be extended to treat string, object, etc as special values and it could be supported that way.

Also, another thing to consider, it's currently quite tedious to write custom validators for inputs as you have to bypass all logic provided by React. Wouldn't it perhaps be reasonable to have something like React.PropTypes.string.restrict(callback) which does the type test for you and you could easily test for say value !== '', it's also more descriptive.

@ghost ghost assigned zpao Jan 8, 2014
@zpao
Copy link
Member

zpao commented Jan 8, 2014

What if we just made React.PropTypes.isRequired work? Adding any in there feels like writing code just to write code. Though it does conform to the same pattern, so nobody would accidentally write isRequired.string. Any thoughts @yungsters?

@sophiebits
Copy link
Collaborator

React.PropTypes.isRequired doesn't read properly to me. I'm okay with .any.isRequired.

@zpao
Copy link
Member

zpao commented Jan 11, 2014

d14ce00

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

4 participants