Search code examples
flowtypestyled-componentsflow-typed

Flow type & Styled-components errors when imported


I'm on win 7. Code:

// @flow
import React from 'react';
import styled from 'styled-components';

Errors:

... many lines of errors
Error: node_modules/styled-components/lib/utils/create-broadcast.js.flow:20
 20:       listeners.forEach(listener => listener(currentValue))
                                                  ^^^^^^^^^^^^ unused

function argument
 10:   subscribe: (listener: () => void) => () => void
                           ^^^^^^^^^^ function type expects no arguments

Error: node_modules/styled-components/lib/utils/create-broadcast.js.flow:26
 26:       listener(currentValue)
                    ^^^^^^^^^^^^ unused function argument
 10:   subscribe: (listener: () => void) => () => void
                               ^^^^^^^^^^ function type expects no arguments

Error: node_modules/styled-components/lib/utils/getComponentName.js.flow:4
  4: export default function getComponentName(target: ReactClass<*>): string {
                                                      ^^^^^^^^^^^^^ identifier `ReactClass`. Could not resolve name


Found 24 errors
error Command failed with exit code 2

.flowconfig:

[ignore]
./build/.*
./node_modules/.*

[include]

[libs]

[lints]

[options]
suppress_comment=.*\\$FlowFixMe

[strict]

The package.json file is below:

"flow-typed": "^2.2.3",
"flow-bin": "^0.59.0",
"styled-components": "2.0.0",

Used project scaffold from https://github.com/react-boilerplate/react-boilerplate @ 3.5.0

I saw in a comment to use libdef 1.4, but when I run yarn add --dev [email protected] I only get version 1 or version 2.x.x, but no 1.4.

What to do next?


Solution

  • If you want flow to stop checking node_modules you can either ignore them in .flowconfig or include only your source files.

    To ignore everything in node_modules:

    [ignore]
    .*/node_modules/.*
    

    Pay attention:

    These regular expressions match against absolute paths. They probably should start with .*

    More info here