flowtype.s

Why

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.

Checks

Examples

// @flow comment

Good example

// @ 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.

⛔️ Bad example

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.

Exact object types

Good example

// @ 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.

⛔️ Bad example

// @ 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)

Last updated