codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

How to use Glow to make your errors stand out in Flow

Trevor-Indrek Lasn
codeburst
Published in
4 min readFeb 2, 2018

Image taken from the official repository

I stumbled upon a cool project which might be of interest to all of you Flow fans. ❤

What is Flow?

Flow is a static type checker for Javascript.

Flow drastically reduces bugs and helps us navigate our code.

Javascript is a loosely typed language — by default, we don’t define types for our variables, function arguments, and so on. Flow is a great way to add static typing to our Javascript.

Here’s how a “loosely” typed add function might look. Loosely typed, meaning there is no type checking going on.

Here’s how we would write the add function with Flow included.

Noticed we added the // @flow comment at the top and added type checking for our function parameters. Essentially, we are telling Javascript the following: please make sure the arguments are numbers, and if they’re not, throw me a feedback error.

Great for avoiding bugs.

But what happens if we insert a string instead of a number to add()? Here’s where Glow comes into play. Glow is an error handler for Flow.

Glow error handling in action

Looks slick! How do we set it up and try it out?

I’m glad you asked!

Let’s start a fresh React project with Flow + Glow.

Paste this command in your terminal.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (4)

Write a response