Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Why PropType.boolean is function #33

Closed
tdimdimich opened this issue Apr 20, 2017 · 4 comments
Closed

Why PropType.boolean is function #33

tdimdimich opened this issue Apr 20, 2017 · 4 comments

Comments

@tdimdimich
Copy link

Modal.propTypes = {visible: PropTypes.boolean}

Warning: Failed prop type: Modal: prop type visible is invalid; it must be a function, usually from React.PropTypes.

I think that the boolean type should be called 'boolean'
You can add boolean as alias for bool, for expected behavior PropTypes

I think if undefined PropType shouldn't be function

@gouegd
Copy link

gouegd commented Apr 25, 2017

PropTypes.boolean is undefined. You get a warning because React expects a function.
PropTypes.bool, like PropTypes.string and others, is a function that validates your props (so it can't be a boolean, a string, etc).

(That said, having an alias for bool as boolean would probably be a good thing)

@gaearon
Copy link
Contributor

gaearon commented May 3, 2017

Yes, it’s expected (you needed PropTypes.bool as documented in the README). Perhaps the warning could say Have you misspelled a PropType? at the end if the validator is undefined. Would either of you be interested in sending a PR to make the warning better?

@gouegd
Copy link

gouegd commented May 4, 2017

I can probably have a go at this next week if nobody does before.

@jonleung
Copy link

jonleung commented Oct 6, 2017

👍

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

No branches or pull requests

4 participants