-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add TypeScript support for styled-component "as" prop. #1796
Add TypeScript support for styled-component "as" prop. #1796
Conversation
💥 No ChangesetLatest commit: e00c57b Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂 If these changes should be published to npm, you need to add a changeset. Click here to learn what changesets are, and how to add one. Click here if you're a maintainer who wants to add a changeset to this PR |
Please note that we are unlikely to merge this into v10 line as we are already preparing v11. Could you please change the base branch and rebase? I'm going to look into it then, for now I've pinged @JakeGinnivan who has worked hard to improve our v11 typings so he can take a look at the proposed approach. |
@riley-rangel do you have a code base you are testing this change on. Could you run |
@JakeGinnivan Those changes don't use any extra mapped types from what I can see. Do conditional types lead to perf problems as well? |
I think |
Taking a quick look on https://github.com/JakeGinnivan/emotion-types-sandbox Here are the results (a single basic styled component). Before: After: A 12% increase in memory usage and 14% increase in the number of types. |
Also just checked in our project Before: After Also, I got a compilation error on
src/styleguide/src/common/Nav/nav.tsx:68:35 - error TS7006: Parameter 'i' implicitly has an 'any' type. Not quite sure what the go is, but it has lost some ability to infer correctly with the change. |
It's an annoying trade off, the smarter you make your types the more intermediate types which get created during compilation. I'm working with someone on the TypeScript team trying to narrow down the patterns in CSS-in-JS libraries in general which are causing these type explosions so hopefully we can fix it in the compiler itself. |
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.
With the perf issues this introduces currently I'm not sure it's worth trying to fix it. We have the .withComponent, but when using as
it just is not type safe?
My vote is to not land this for now, I'm just not sure the perf issues are worth the better types at this stage.
Other than that - from what I understand this has introduced a regression (@JakeGinnivan's |
Sorry guys, with everything going on, I haven't had time to check back on this. In terms of the regression and the performance hit, I will look into trying to resolve these issues. @JakeGinnivan Thanks for the hint on how to check performance on this. I wasn't aware of this before, so I will enjoy reading up more on that. I will try to refactor w/o mapped types as well. Still learning about TypeScript, so this will be an awesome opportunity to learn more. @Andarist Thank you for pointing out this PR to @JakeGinnivan. I will continue to work on this on the side as time permits, but in the meantime, if you'd like to keep the PRs list clean, we can close this. I have plenty of things that can help point me in the right direction on this one for now. |
@riley-rangel k, I'm going to close this for now, but I'm happy to reopen this whenever you ping me to do so. Please also note that this has 0 chance to hit the |
@riley-rangel no worries, happy to help. |
What: Add TS support for styled-component
"as"
prop.Why: Improves overall DX when using
"as"
prop.How: Alongside emotion styled-components living in separate repo.
Checklist:
Other Comments:
Been using this package for over a year now, and I love it. One thing that I noticed it was missing was TS support for the
"as"
prop. It's such a powerful feature that our team enjoys using in the right situation, but the type omission is a bummer. We've been iterating on various TypeScript definitions for it, and I've had some extra time, so wanted to give this a shot here. If anyone has any suggestions or recommendations, please throw a comment up below!Relates to:
#1137