question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flow doesn't return error with styled-components

See original GitHub issue

Environment

Binaries:

  • Node: 10.12.0 - /usr/bin/node
  • Yarn: 1.10.1 - /usr/bin/yarn
  • npm: 6.4.1 - /usr/bin/npm

npmPackages:

  • babel-plugin-styled-components: ^1.5.1 => 1.5.1
  • styled-components: ^4.0.0-beta.10 => 4.0.0-beta.10

Reproduction

  1. git clone https://github.com/ravecat/styled-components-toolbox.git --single-branch --branch feature/migrate-to-flow
  2. yarn
  3. git commit --amend and can see console output

$ flow check Found 0 errors

Steps to reproduce

Create Button.js file with flow. Specifically indicated the wrong type for the variable (highlighted comment)

Button.js

/* @flow */
import React from "react";
import styled, { css, type ReactComponentStyled } from "styled-components";
import BaseComponent, { BaseProps } from "common/components/BaseComponent";

type ButtonProps = BaseProps & {
  type?: string,
  href?: string,
  disabled?: boolean
};

const Button = ({ children, ...rest }: ButtonProps) => (
  // TODO Set wrong type for test flow
  <Wrapper as="button" type={42} {...rest}>
    <span>{children}</span>
  </Wrapper>
);

const Wrapper: ReactComponentStyled<ButtonProps> = styled(BaseComponent).attrs({
  type: ({ type }) => type || "button"
})`
  display: inline-block;
  height: 32px;
  padding: 0 15px;
  line-height: 30px;
  text-align: center;
  letter-spacing: normal;
  cursor: pointer;
  outline: 0;
  white-space: nowrap;
  color: ${({ theme }) => theme.textColor};
  background: ${({ theme }) => theme.primaryColor};
  border: 1px solid ${({ theme }) => theme.primaryColor};
  border-radius: 0;

  :hover {
    background: ${({ theme }) => theme.textColor};
    color: ${({ theme }) => theme.primaryColor};
  }

  ${({ disabled }) =>
    disabled &&
    css`
      && {
        cursor: default;
        background: ${({ theme }) => theme.textColor};
        border-color: ${({ theme }) => theme.dividerColor};
        color: ${({ theme }) => theme.dividerColor};
      }
    `};
`;

export default Button;

Expected Behavior

Flow return error

Actual Behavior

Flow check without error

Probably, this issue related with https://github.com/styled-components/styled-components/issues/1349 , but I cannot get answer on that problem.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ravecatcommented, Nov 18, 2018

Yep, absolutely right. As I understand current issue depends on lack of libdef? if it is true you can close issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flow doesn't return error with styled-components · Issue #2201 ...
Flow doesn't return error with styled-components #2201 ... --branch feature/migrate-to-flow; yarn; git commit --amend and can see console output.
Read more >
Flow type & Styled-components errors when imported
I saw in a comment to use libdef 1.4, but when I run yarn add --dev flow-typed@1.4 I only get version 1 or...
Read more >
API Reference - styled-components
Returns a StyledComponent that does not accept children. Place it at the top of your React tree and the global styles will be...
Read more >
Using Styled Components and Flow with Create React App
If you try importing styled-components, you will notice that flow complains that it cannot find the module. This is because styled components ...
Read more >
How to use styled-components with React Native
In this tutorial, we'll discuss what advantages a library like styled-components has over the general StyleSheet manager in React Native.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found