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

Make StyledComponent polymorphic #1588

Merged
merged 11 commits into from Nov 5, 2019

Conversation

FezVrasta
Copy link
Member

@FezVrasta FezVrasta commented Oct 29, 2019

What:

implements/fixes #1587

Why:

read #1587

How:

StyledComponent is now polymorphic (just for the CreateStyled function)

Checklist:

  • Documentation
  • Tests
  • Code complete
  • Changeset

this gets rid of a lot of warnings and wrong auto formatting
This makes it possible to type styled functional components and enables a workaround for lack of tagged templates support of Flow
@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2019

🦋 Changeset is good to go

Latest commit: 87e720a

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

@FezVrasta
Copy link
Member Author

FezVrasta commented Oct 29, 2019

I tested this on my own (very large - ~1k styled components) application.

I noticed an issue in the following case:

// ↓↓↓ Flow error, it requires us to annotate its props
const Container = styled.div();

export default () => <Container />;
// ↓↓↓ This works
type Props = { children: React$Node };
const Container = styled<Props>('div')();

export default () => <Container />;

I'm not sure why it's asking me to annotate it, since Container is not exported...

If I change it to this, it doesn't require any annotation, so it looks like Flow detects Container is the root "tag" of the exported component and requires us to be explicit about its properties...

// ↓↓↓ Flow error, it requires us to annotate its props
const Container = styled.div();

export default () => (
  <>
    <Container />
  </>
);

Do you think is it alright or there's something off?

ps: here's a repro if you want to play with it:

https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoAlgWwA5wE4AuYASgKYCGAxkVHnJmAOR4XWMDcGO+RBAntlJgA3mACiMUplIA7AgBUBpADRgAygXIFSkgM66AYgFcZ1dHBnkYAYXq4ZsogF8wtekxZUCjVKlIAPXEIwfkEwAEk5UjxcGC1zGV0wAF4wAEE8PHI+AB5yGT4APl8AoN4ldX5JABMAeWwCBKTU4VQwMDiAIx0AfgAuMF0CPHQZAHNlNsGACzgjGGqDfARyPGqABTpsfsHh0bGUwrBOuDhJfMn2zTwx0gIdoZHx1CcSwJ4Qio0+GttuBzkOXWR1SGi0OlI+mMpkaFisf3sjiBRwAZCIptVSFByPMCJs4NhdAN8nxLiE4BonmMBgAKACUh12VLJCHQBGmCIsjlpU3aDn8CnI1PEkmkckUgjJfICBHqsMSO2+NTlTSmDOSRyVpGqnIBBGRLzeZU+YU26AAbuCtTq7FzAcCUpUftrdUiHWjWu0APpeqRweVezwwAbW132wpkn1+gOdci6UjEgqR32Yf0JL1DZ1EsAk5PR9NQZarDZbRN8Q2oUJCayebSh216x3ImlTAB07dWY2zkW0MTO8QsulQ6s1VRdDbdxUrFRrFDrY+qjs9YGbvJCQoGEikjglKjXBPlukVC5Vg7VtPbrc73aifbih5HTt+E-DZIA2gBrUh8AaPfYAXQGWcrQXMMCDJTpRmqWlH2A+dnWqCtKEHIhMxqIDa1Ia1HRpGR5mDHMCjpTh2lI9o1zI1BgGAMAAHVpj4MBqjgMAECEBxtXJQiZH9cEQmmdAki5HpUGQxIiFsORyFGaI0kdNDtVbaoLQAAymZD4DwAYWGqTgVJIsjSIooyxKGMBJM0GS8AAIXkhclNU9SznwbTtT0zhfCrMB8UJJcnE4UoPlMogPxY1IaWwLZsx83RHxbdocgs6SHDwNJijIws4CmHJgCSqy0uHAzDLAPx3mCYKwDgD8cMigloqiuLsvS0jEosSyUus5qMtONccryjrmpy4piKAA

I opened an issue on the Flow repo: facebook/flow#8166

@codecov
Copy link

codecov bot commented Oct 29, 2019

Codecov Report

Merging #1588 into master will not change coverage.
The diff coverage is 100%.

Impacted Files Coverage Δ
packages/styled/src/index.js 100% <ø> (ø) ⬆️
packages/styled-base/src/utils.js 100% <100%> (ø) ⬆️
packages/styled-base/src/index.js 100% <100%> (ø) ⬆️

@Andarist
Copy link
Member

Do you think is it alright or there's something off?

I'm not sure - I don't know Flow's philosophy. The fact that a fragment there changes the situation there is kinda wild for me 😱 Maybe this is something you could ask Flow maintainers? Not sure how often they respond nowadays though.

@FezVrasta
Copy link
Member Author

FezVrasta commented Oct 30, 2019

@FezVrasta
Copy link
Member Author

@nmote gave me a very clear explanation here facebook/flow#8166 (comment)

So everything is correct, I'll fix the CI and we can then merge it.

@Andarist
Copy link
Member

Sure, just let me know when this is ready. Thanks for working on this!

@FezVrasta
Copy link
Member Author

hopefully CI should pass now, this lint rule that prevents semicolons is killing me...

@FezVrasta
Copy link
Member Author

I would like to add a page in the docs where I explain how the Emotion Flow types work, any idea where would it make sense to put it?

@Andarist
Copy link
Member

hopefully CI should pass now, this lint rule that prevents semicolons is killing me...

Isn't precommit hook just fixing this for you automatically?

I would like to add a page in the docs where I explain how the Emotion Flow types work, any idea where would it make sense to put it?

I would say that the best place is just under TypeScript in the Tooling section

@FezVrasta
Copy link
Member Author

@Andarist I added the new documentation page, feel free to merge the PR if you think it's okay.

@FezVrasta
Copy link
Member Author

hopefully CI should pass now, this lint rule that prevents semicolons is killing me...

Isn't precommit hook just fixing this for you automatically?

In the case I hit, Prettier needed to run several times to properly format the code (razzle/index.js), and for some reason it doesn't like the fact we had some empty lines between two code blocks...

# Conflicts:
#	packages/styled-base/src/utils.js
@Andarist Andarist changed the base branch from master to next November 4, 2019 22:43
Copy link
Member

@Andarist Andarist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems OK for me, but would love @mitchellhamilton having a look at this too.

@emmatown emmatown merged commit 2293547 into emotion-js:next Nov 5, 2019
@github-actions github-actions bot mentioned this pull request Nov 5, 2019
louisgv pushed a commit to louisgv/emotion that referenced this pull request Sep 6, 2020
* chore: tell Prettier we are using Flow

this gets rid of a lot of warnings and wrong auto formatting

* fix: make CreateStyled callable function polymorphic

This makes it possible to type styled functional components and enables a workaround for lack of tagged templates support of Flow

* chore: update type annotation to use new style

* fix: wrong formatting

* style: fix prettier issues

* chore: changeset

* fix: just import the @emotion/sheet type

* style: make prettier happy

* docs: added Flow types documentation page

* Update flow.mdx

* refactor: rename P to Props

# Conflicts:
#	packages/styled-base/src/utils.js
@github-actions github-actions bot mentioned this pull request Nov 10, 2020
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

3 participants