WIP: Adding type definition to recompose
It's hard to keep prop types of underlying components of HOCs. Even the official documentation is not working well. It's even harder to have multiple HOCs typed and maintain with peer developers. Here comes recompose
, the HOC utility module. If we have recompose
properly typed, we can omit typing of our own HOCs taking advantage of recompose
and flowtype's type inference.
recompose
still doesn't have official flowtype definition, but there are some efforts:
This gist is an effort to make it happen based on the PRs above.
props
props
by HOCrecompose
T | Fn1<A, B>
Fn1<A, B> | T
HOC<$Shape<A & B>, B>
. In this way, the underlying component can ignore some unnecessary intermediate props.
const withOpen = withValue(false, (open, setOpen) => ({ open, setOpen }));
const withToggle = withProps(({ open, setOpen }) => ({ toggle: () => setOpen(!open) }));
// `Something` doesn't need `setOpen`!
function Something({ open, toggle }) { /* ... */ }
const enhancedSomething = compose(withOpen, withToggle)(Something);
suppress_comment
suppresses also next next line in addition to next line. So put a new line after the suppression target line.
For example:
// .flowconfig
[options]
suppress_comment=^ $ExpectError$
// or
suppress_comment=\\(.\\|\n\\)*\\$ExpectError
// $ExpectError
'foo'.bar();
'foo'.bar(); // This line's error is also suppressed!
// $ExpectError
'foo'.bar();
'foo'.bar(); // This line's error is not suppressed!