-
Notifications
You must be signed in to change notification settings - Fork 671
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
Convert components package to TS #692
Convert components package to TS #692
Conversation
Hey @PaulieScanlon, I'll take a look at your errors. Can I open a PR targeted at your fork? Or do you have any questions / problems I could help you with? |
@hasparus hey! Most of the issues I’m struggling with relate to the ref. You’ll probably see the TODO comments next to the ones I couldn’t work out. You can open PR on my fork no worries! Thanks for stepping in, I appreciate it! |
Hey, sorry it took so long. I started working on today and I know what's wrong. I usually don't encounter these problems, because I don't use Okay, if Box was declared as function, we could make it generic, make the props generic and infer what the We can't make it generic easily. We'd have to build on top of I see you've added I believe we have a regression in comparison with @types/theme-ui__components. I mentioned in #121 that few packages here would be very easy to convert. A small example what happened when I tried to fix one of the errors: I'm working around it with a small hack: I wonder where do we stand between prioritizing ease of development vs user DX. I'll send you a PR today @PaulieScanlon, but I think this will need some more work from us, especially in tests. |
__themeKey="text" | ||
css={{ | ||
fontFamily: 'heading', | ||
fontWeight: 'heading', //TODO |
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.
Isn't this a bug? css
is passed to styled component without touching theme. Shouldn't this be __css
?
cc @jxnblk
https://github.com/system-ui/theme-ui/blob/master/packages/components/src/Box.js#L13-L30
Edit: Yeah. It gets emitted to css.
a snapshot
.emotion-0 {
box-sizing: border-box;
margin: 0;
min-width: 0;
font-family: heading;
font-weight: heading;
line-height: heading;
font-size: 32px;
}
<h2
className="emotion-0"
/>
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.
Hey @hasparus thanks for looking into this... what would you say is next step is? I'd like to help out but you lost me at the forward ref generics.
Is there anything i can be investigating or is there a bigger conversations that needs to happen about this package?
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.
The ForwardRef generic could be probably dropped tbh. TS would infer proper types if we annotate component props and ref. The problem is, components with "as" prop are tricky to type. We should write some tests to check their public api on type level (inference of onClick event would be perfect, not sure if we can achieve it with Box).
We could change "as" prop usages to withComponent, to get rid of the errors, but I’m not sure if we want to, as this would have a small runtime cost. We’d probably be fine with few as any assertions.
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.
Good catch! This does look like a bug, e.g. css
prop should be __css
Just checking if there is any movement on this PR? what needs to happen, apart from the conflict, to get this merged? |
@mrmartineau I'm adding types "the easy way" in this commit d06b4c2. I expect this might get merged before we tackle problems in this PR the hard way. I suppose current state of our work on TS adoption in @theme-ui/components is in my PR to Paullie I drafted an idea for further work in #703 (comment). I'll copy it here for convenience.
I would like to work on this, because TS Emotion support for |
@hasparus would removing the |
yes If we define Box as a function and instead of using I'll give a shot this @emotion/styled-base fix today after work to at least estimate how much time it would take. |
Okay, I did some research. New info: There is a closed PR from a week ago emotion-js/emotion#1796 adding the They're simplified on the next branch for new major version of emotion, but they'll still be big. This leads to a choice. We can either
I assume we would like to support BTW It already works for Field in DefinitelyTyped. Not sure if I mentioned that.
|
Hi, @hasparus any luck solving that emotion-styled issue? Does this need any technical implementation on the The emotion-js/emotion#1796 PR got closed for now so I don't think we'll be getting it anytime soon. Have we considered the option of porting over https://github.com/emotion-js/emotion/blob/master/packages/styled-base/types/index.d.ts into Considering that Any thoughts? |
Hey @ivoreis
@jxnblk mentioned it in #692 (comment)
@dburles entirely got rid of all of our problems with This will greatly simplify any TS related work here, so I suppose we just wait until #823 is merged and the only thing we need to type is |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/systemui/theme-ui/cptpjsndv |
Great PR, looking forward to having native typescript implementation, but can I suggest we start converting components to ts after merging #1368 as there will be significant changes |
This would still be amazing to do, but since we let this PR go stale there’s quite a lot of merge conflicts now. So sorry for this sucky experience @PaulieScanlon—if you’re still interested we’d still love this work to happen. Really appreciate your time. |
Hey all, here's a first "incomplete" pass at converting the components package to TypeScript.
I'm afraid i've run out of "talent" in a number of places so have left TODO comments where i'm not able to resolve the TypeScript errors.
Could someone perhaps give me some pointers and i'd be happy to give it another shot!
Thanks