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

Auto infer StyledComponent type from shorthand #3766

Open
penx opened this issue Mar 6, 2020 · 0 comments · May be fixed by #3767
Open

Auto infer StyledComponent type from shorthand #3766

penx opened this issue Mar 6, 2020 · 0 comments · May be fixed by #3767

Comments

@penx
Copy link
Contributor

penx commented Mar 6, 2020

Do you want to request a feature or report a bug?

Feature

What is the current behavior?

// @flow
import type { StyledComponent } from 'styled-components';

import styled from 'styled-components';

const Blue: StyledComponent<empty, empty, HTMLDivElement> = styled.div`
  border: 1px solid blue;
`;

const Red = styled.div`
  border: 1px solid red;
`;

export { Red, Blue };
Missing type annotation for StyleProps. StyleProps is a type parameter declared in function type [1] and was implicitly
instantiated at encaps tag [2].

     src/App.js
       7│   border: 1px solid blue;
       8│ `;
       9│
 [2]  10│ const Red = styled.div`
      11│   border: 1px solid red;
      12│ `;
      13│
      14│ export { Red, Blue };
      15│

     flow-typed/npm/styled-components_v5.x.x.js
 [1] 255│     [[call]]: <StyleProps, Theme>(
     256│       string[],
     257│       ...Interpolation<PropsWithTheme<StyleProps, Theme>>[]
     258│     ) => StyledComponent<StyleProps, Theme, V>,

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

Red should auto resolve to type StyledComponent<empty, empty, HTMLDivElement> (or less ideal StyledComponent<empty, empty, any>)

If this is a feature request, what is motivation or use case for changing the behavior?

Auto infer types will reduce a lot of refactoring (type insertion) needed when introducing flow in to existing code.

Related, any projects using styled-components/macro are going to start seeing a lot of issues via #3762 so it would be good to auto resolve as many of them as possible.

penx added a commit to penx/flow-typed that referenced this issue Mar 6, 2020
@penx penx linked a pull request Mar 6, 2020 that will close this issue
tommoor added a commit to outline/outline that referenced this issue Aug 9, 2020
The current flow-typed def requires an insane amount of manual typing that just doesnt
make any sense. Restoring the old definition for now:
flow-typed/flow-typed#3766
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 a pull request may close this issue.

1 participant