-
Notifications
You must be signed in to change notification settings - Fork 526
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
Avoid tokens weird type checking/eliding #2762
Conversation
🦋 Changeset detectedLatest commit: 3ea4e32 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
size-limit report 📦
|
@@ -1,14 +1,15 @@ | |||
import React, {forwardRef, MouseEventHandler} from 'react' | |||
import Box from '../Box' | |||
import {merge, SxProp} from '../sx' | |||
import {BetterSystemStyleObject, merge, SxProp} from '../sx' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this was caused by the fact that these props aren't equally defined across all polymorphic types, and forwardRef swallows polymorphism, making things wonky.
This makes perfect sense!
I think we would be well served extending our type tests further to cover most/all components, as I'm sure others are limited in the same or similar ways.
Thanks for the suggestion ✨ I see there are type tests for quite a few components but the recent ones seem to lack of them. I'll chat with the team about it.
This looks great to me! 🚀 Thanks for raising this PR 🙏🏼
Would there be a good place to learn more about how For the type tests, is this something that should be a part of the testing requirements for components/props added or changed in a component? It doesn't really seem like there are other alternatives to guarantee that things are showing up, curious if there are other approaches that teams use or if this is kind of our best best moving forward to catch issues like this. Would love to hear your thoughts! |
I don't know of one offhand, but a quick search brings up things like https://fettblog.eu/typescript-react-generic-forward-refs/ the crux of the issue is that a HOC in a static context can't return a generic that infers from an internal generic which seem related. Which is a mouthfull but this might be more easy to grok the types for forwardRef don't return a component that's possible of generically defining something based on a certain prop, so it effectively 'swallows' up the as prop (which can't be inferred because it can't be defined)
I think there definitely should be some level of requirement for adding these, even if they're only limited in the scope of the props validated! |
Not sure offhand whether this would be something we want to land in the current/next release - so feel free to merge when it makes sense (I don't want to merge too early!) |
@mattcosta7 makes perfect sense, thanks so much! @broccolinisoup I'm going to merge this is as the follow-up to the TODO from: #2760 if that makes sense, let me know if it makes the release more complicated and I'd be happy to revert/add it back in after the release 👍 |
Describe your changes here.
Relates to #2760
In this pr we omitted
onResize
andonResizeCapture
as typescript was causing these to elide a mandator unknown type, which was super confusing.I believe this was caused by the fact that these props aren't equally defined across all polymorphic types, and forwardRef swallows polymorphism, making things wonky.
I've re-typed these components using the polymorphic helper, and added some type tests to help validate they don't regress. I think we would be well served extending our type tests further to cover most/all components, as I'm sure others are limited in the same or similar ways
Screenshots
Please provide before/after screenshots for any visual changes
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.