Skip to content
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

Merged
merged 4 commits into from
Nov 14, 2019

Conversation

JakeGinnivan
Copy link
Contributor

@JakeGinnivan JakeGinnivan commented Nov 11, 2019

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:

  • Documentation
  • Tests
  • Code complete
  • Changeset

If we like this solution I can add docs

@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2019

🦋 Changeset is good to go

Latest 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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 11, 2019

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:

Sandbox Source
Emotion Configuration

): CreateStyledComponent<PropsOf<C> & { theme?: Theme }, {}, { theme: Theme }>

<
Copy link
Contributor Author

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

@Andarist
Copy link
Member

Does this cover the use case described in #1272? Is it possible to create a styled HTML element with custom shouldForwardProp in such a way that we prevent forwarding a certain prop X and thus we can specify a type for that X prop that is different than the one defined on JSX.IntrinsicElements[some_type].

Not sure what the best real-life example for this is but let's assume div & color prop - which has currently a string type - but we'd like to make it an array of strings.

@JakeGinnivan
Copy link
Contributor Author

JakeGinnivan commented Nov 11, 2019

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

@Andarist
Copy link
Member

Could you add this as a test case?

@JakeGinnivan
Copy link
Contributor Author

@Andarist done

@Andarist
Copy link
Member

Could you add a changeset for this? And ideally a short note in the docs?

@JakeGinnivan
Copy link
Contributor Author

@Andarist done, also added overload for normal components too

@Andarist
Copy link
Member

Unfortunately, you need to resolve conflicts on this one.

@JakeGinnivan
Copy link
Contributor Author

@Andarist rebased

@Andarist Andarist merged commit ad77ed2 into emotion-js:next Nov 14, 2019
louisgv pushed a commit to louisgv/emotion that referenced this pull request Sep 6, 2020
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants