PropTypes and Flow cover similar things, but use different approaches. PropTypes can give you warnings at runtime, which can be useful for quickly finding incorrect answers coming from the server, etc. However, Flow seems to be the future, and with concepts like generics, it is a very flexible solution. Also, autocomplete offered by Nuclide is a big plus for the flow.
Now my question is the best way to start a new project. Or could it be a good solution to use both Flow and PropTypes? The problem with using both is that you write a lot of duplicate code. This is an example music player application that I wrote:
export const PlaylistPropType = PropTypes.shape({ next: ItemPropTypes, current: ItemPropTypes, history: PropTypes.arrayOf(ItemPropTypes).isRequired }); export type Playlist = { next: Item, current: Item, history: Array<Item> };
Both definitions basically contain the same information, and when the data type changes, both definitions need to be updated.
I found this babel plugin to convert type declarations to PropTypes, which might be the solution.
reactjs react-proptypes flowtype
danielbuechele Mar 17 '16 at 15:37 2016-03-17 15:37
source share