acdlite / recompose

A React utility belt for function components and higher-order components.
MIT License
14.76k stars 1.26k forks source link

compose function results typed as 'any' #580

Open fragosti opened 6 years ago

fragosti commented 6 years ago

I've been setting up a new project to use recompose + flow and everything is working great except that flow coverage is not 100% because apparently flow is inferring type any the compose function.

Here is the example code:

// @flow
import React from 'react';
import { compose, pure, withStateHandlers } from 'recompose';
import type { HOC } from 'recompose';
...
const enhance: HOC<*, Props> = compose(
  pure,
  withStateHandlers(
    { isShowing: false },
    {
      show: () => () => ({ isShowing: true }),
      hide: () => () => ({ isShowing: false }),
    }
  )
);

export default enhance(App);

Both Visual Studio Code and flow coverage tell me that I have some uncovered code, and VSC shows that it's because compose has type 'any'. Also I tried manually using the $Compose util type but VSC says it's typed to any as well.

react: 16.2.0 recompose: 0.26.0 flow-bin: 0.61.0 flow-typed: 2.2.3

flow-typed install recompose results in these being the definitions.

istarkov commented 6 years ago

we have here examples, tests etc with flow, may you just look there

fragosti commented 6 years ago

@istarkov the issue is basically that the flow types are being loaded for some of the api but not other parts. I seem to be able to load the types for pure and withStateHandlers but not for compose. Might not be an issue with recompose.

istarkov commented 6 years ago

Have you tried to use flow type defs not from flowtyped repo but directly downloading them here and including https://github.com/acdlite/recompose/blob/master/types/flow-example/.flowconfig#L9

And it will be good to provide simple example at github so anyone can reproduce just cloning it.