react-create-app/flow-type doesn't work correctly

144 Views Asked by At

When i write functional components and describe prop types as flow it doesn't recognize that. Example below should throw an error because props.some isn't a string it is actually a number.

// @flow

import React from 'react'
import {compose, withProps} from 'recompose'

const
  App = (props: {
    some: string
  }) => <div className='App'>{props.some}</div>

export default compose(
  withProps({
    some: 42
  })
)(App) //Response => No Errors

In other cases such (e: string) => e; e(42); // => Error flow-type works fine.

My .flowconfig is only after flow init.

2

There are 2 best solutions below

0
On

I think the issue here is getting the types for the recompose library. Without that, Flow has no way to know what the type of the wrapping component should be. Have you installed a libdef for recompose?

0
On

Installed flow-typed helped. And there is an article of how to install flow-type with recompose