Owner: Tycho Tatitscheff
Flowtype is awesome:
- it successfully replaces unit tests for some tasks, like ensuring that the different parts of the app, remains in sync with each others.
- it give you autocompletion
That being said, if flow is misconfigured and you blindly trust the result, you can still have bug where it should have raised an alert for you.
- Every
*.js
file should have a comment on first line of the code with// @flow
.- Why?
- If it is not, the file is ignored by flow.
- Why?
- Every types should use exact typing
{|...|}
and not{...}
// @ flow
import React from "react";
// rest of the file
class Comp from React.Component {
}
If you make a typo in React
, you can see it, for instance.
import React from "react";
// rest of the file
class Comp from React.Component {
}
If you make a typo in React
, you can don't see it.
// @ flow
type PropsType = {|
goats: Array<string>
|}
const Herd = (props: PropsType) => (<View><Text>{props.goats.length}</Text></View>)
If you make a typo in PropsType
, you can see it.
// @ flow
type PropsType = {
myFavoriteGoat: string
}
const Herd = (props: PropsType) => (<View><Text>{props.myFavoriteGoat}</Text></View>)
(myFavoriteGoat
should raise an error, but don't since PropsType
are not exact)