You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Regardless, I'd (incorrectly) expected types for these - and thought a disclaimer to this effect might be helpful to others. Feel free to close if you feel otherwise. Otherwise I'm happy to submit a PR.
I expect that the simplest way to get strongly typed primitives is to write wrapping components for the various DOM primitives that are strongly typed - in the spirit of react-primitives, but sticking to DOM spec - this is something I've been looking into for use in my own projects.
We would find it extremely useful to type check props on intrinsics.
That appears to be what the issue title is about, but not what @mwalkerwells's clarification points to, unless I'm misunderstanding. As a simpler example, I'd expect this to fail:
<divstyle={1}bogus="allowed">Test</div>;
We sometimes spread props into intrinsic components, and it would be valuable to know when we've spread something that includes props React doesn't expect there, or of the wrong type.
Also, it would be extra nice to have, for instance, <button>'s onClick prop automatically typed as (SyntheticEvent<HTMLButtonElement>) => void. We've passed handlers expecting to be attached to the wrong kind of DOM element before, and this would catch that.
The libdef has been moved to flow-typed. If you want to make improvements, please make PR over there. We have upstreamed a much more complete version there
Activity
mwalkerwells commentedon Apr 22, 2017
You mean add a disclaimer that the default return type of
renderis?React$Element<any>?https://github.com/facebook/flow/blob/master/lib/react.js#L32
Not sure how useful that would be. If you need more type safety, you can easily add it:
aldendaniels commentedon Apr 24, 2017
@mwalkerwells Yeah, that's what I mean - there are not type defs for the React primitives and it's not clear how to provide any. By contrast, Typescript documents how to provide your own types for JSX intrinsics.
Regardless, I'd (incorrectly) expected types for these - and thought a disclaimer to this effect might be helpful to others. Feel free to close if you feel otherwise. Otherwise I'm happy to submit a PR.
I expect that the simplest way to get strongly typed primitives is to write wrapping components for the various DOM primitives that are strongly typed - in the spirit of react-primitives, but sticking to DOM spec - this is something I've been looking into for use in my own projects.
Peeja commentedon Jan 30, 2018
We would find it extremely useful to type check props on intrinsics.
That appears to be what the issue title is about, but not what @mwalkerwells's clarification points to, unless I'm misunderstanding. As a simpler example, I'd expect this to fail:
We sometimes spread props into intrinsic components, and it would be valuable to know when we've spread something that includes props React doesn't expect there, or of the wrong type.
Peeja commentedon Jan 30, 2018
Also, it would be extra nice to have, for instance,
<button>'sonClickprop automatically typed as(SyntheticEvent<HTMLButtonElement>) => void. We've passed handlers expecting to be attached to the wrong kind of DOM element before, and this would catch that.motiz88 commentedon Aug 6, 2018
I'd like to claim this issue please 😃 Will start working on it later this week.
cprodescu commentedon Aug 6, 2018
@motiz88 thank you for taking this on!
SamChou19815 commentedon Mar 4, 2025
The libdef has been moved to flow-typed. If you want to make improvements, please make PR over there. We have upstreamed a much more complete version there