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

styled-components v5: cannot use another styled component as Instance type #3812

Open
walkerdb opened this issue Apr 22, 2020 · 1 comment
Open

Comments

@walkerdb
Copy link

Do you want to request a feature or report a bug?
Bug in styled-components v5 flow types.

What is the current behavior?
Using any styled component as the Instance type of another styled component produces an error. e.g. the following code:

const BasicComponent: StyledComponent<{}, *, HTMLDivElement> = styled.div``;
const SomeOtherComponent: StyledComponent<{}, *, BasicComponent> = styled(BasicComponent)``;

results in this error:

Cannot assign template string to SomeOtherComponent because in type argument Instance [1]:
 • Either AbstractComponent [2] is incompatible with InterpolatableComponent [3].
 • Or statics of InterpolatableComponent [4] is incompatible with InterpolatableComponent [3].

     path/to/example.js
       3│ import type { StyledComponent } from 'styled-components';
       4│
       5│ const BasicComponent: StyledComponent<{}, *, HTMLDivElement> = styled.div``;
 [3]   6│ const SomeOtherComponent: StyledComponent<{}, *, BasicComponent> = styled(BasicComponent)``;
       7│

     flow-typed/npm/styled-components_v5.x.x.js
 [1] 231│     Instance,
     232│     MergedProps = { ...$Exact<Props>, ...CommonSCProps, ... }
 [2] 233│   > = React$AbstractComponent<MergedProps, Instance> &
 [4] 234│     Class<InterpolatableComponent<MergedProps>>;

Local Environment Information
Running on flow 0.123.0 and latest flow-typed defs for styled-components v5

@craigdallimore
Copy link

@walkerdb

I'm having some success with this pattern; it could use a review / explanation from someone more familiar with meaning of Instance within the styled-components typedef as I don't have a concrete intuition for why it appears to type check.

const SomeOtherComponent: StyledComponent<
  {},
  *,
  React.ComponentType<React.ElementConfig<typeof BasicComponent>>
> = styled(BasicComponent)``;

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

No branches or pull requests

2 participants