-
-
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
Created overload of create styled which supports shouldForwardProp be… #1624
Created overload of create styled which supports shouldForwardProp be… #1624
Conversation
🦋 Changeset is good to goLatest commit: 28979b5 We got this. 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 |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 28979b5:
|
packages/styled/types/base.ts
Outdated
): CreateStyledComponent<PropsOf<C> & { theme?: Theme }, {}, { theme: Theme }> | ||
|
||
< |
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 added a new overload to prevent a breaking change of forcing the shouldForwardProp to be a type guard
Does this cover the use case described in #1272? Is it possible to create a styled HTML element with custom Not sure what the best real-life example for this is but let's assume |
Yeah it will do. (edited since original post) export const Box = styled('div', {
shouldForwardProp: (propName): propName is Exclude<keyof JSX.IntrinsicElements['div'], 'color'> => propName !== 'color'
})<{ color: string[] }>(props => ({
color: props.color[0]
}))
;<Box color={['green']} /> Whatever the logic is for filtering out the props, they need to create a type guard of the same time. It's harder for omitting like above. Overall I think it's a good improvement over the casting |
Could you add this as a test case? |
@Andarist done |
Could you add a changeset for this? And ideally a short note in the docs? |
@Andarist done, also added overload for normal components too |
5ce2b9f
to
f94bb81
Compare
Unfortunately, you need to resolve conflicts on this one. |
…ing a custom type guard
Co-Authored-By: Mateusz Burzyński <mateuszburzynski@gmail.com>
8e2e4fa
to
28979b5
Compare
@Andarist rebased |
… being a custom type guard (emotion-js#1624) * Created overload of create styled which supports shouldForwardProp being a custom type guard * Add test case for filtering conflicting props * Add docs and overload for normal components * Update .changeset/polite-tips-attend/changes.md Co-Authored-By: Mateusz Burzyński <mateuszburzynski@gmail.com>
What: A potential solution to #1272
Why: Because shouldForwardProps is a runtime solution to something which is not supported in the type system
How: I have created an additional overload in the create styled function which forces shouldForwardProps to be a custom type guard.
Checklist:
If we like this solution I can add docs