-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
PropType for function argument type checking. #4811
Comments
This won't work in 0.14 where we actually freeze the props object. I'll leave this open for now in case we want to discuss more (@sebmarkbage) but this is probably out of scope for React and would be more appropriate as a general JS type checker, perhaps one that could integrate with Flow. |
Looks like there isn't any more discussion on this topic, out of scope, more appropriate for a general type checker. |
+1 |
I think this is an excellent idea when PropTypes are used for type checking. |
It would be nice to have this feature working with |
I don't see why you wouldn't have PropTypes when also using TypeScript. Those PropTypes will validate at runtime while TypeScript will just do it when compiling. For me, they seem to do very different things. I know this was closed years ago, but I still find this a really useful request. I think I'd be useful to give it a second thought at this whole idea. |
typescript |
i think it's a good idea, because of custom elements using react |
I'd really like to be able to define the type of arguments a prop function should be called with.
I think that this is the last missing piece we need to really define a React component interface. I might not be the only one to feel the need to comment those signatures. But having a way to do it programmatically would be much better.
First attempt
I tried to create a new PropTypes able to do that by wrapping the function given as prop:
It's working but I'm receiving the pretty straightforward warning message:
Warning: Don't set .props.foo of the React component. Instead, specify the correct value when initially creating the element or use React.cloneElement to make a new element with updated props.
.Yeh, mutating the prop is not a nice way but that's the only way I found without modifying React core.
The text was updated successfully, but these errors were encountered: