xingtwittersharerefreshplay-buttonpicture as pdflogo--invertedlinkedinkununuinstagram icon blackShapeGroup 3 Copy 2Group 2 Copydepartment_productdepartment_datascienceuserclosebasic clockblogShapearrows slim right copy 3arrows slim right copy 3arrows slim right copy 3

Type your Javascript: Flow vs Typescript

DieProduktMacher

DieProduktMacher |

27. May 2019 |

- min Lesezeit

Type your Javascript: Flow vs Typescript
Javascript is a widespread programming language with many companies and developers loving it. Especially the ability to quickly implement web applications with almost zero infrastructure requirements led to the popularity of javascript. However, as projects evolve and applications outgrow the initial fast-paced state new tools are required to create big and stable javascript applications at scale. In this blog post, we explain why type systems are useful, how they work and compare the two big ones out there: Typescript and Flow.

Why type Javascript?

The first version of Javascript has famously been created within 10 days by Brandon Eich. What started as a small scripting language within the browser, has become the most popular programming language on Github. But everyone who wrote a really big app in Javascript will tell you: It’s really hard to maintain. No matter how well you test, there are almost always type errors in production code. This can be fixed by adding types to javascript. Typescript and Flow both extend Javascript with extra information about what types are behind each variable. This allows a piece of software, called a type checker, to verify that the code is plausible without even running it. For example, it can verify that values, that are potentially null, are checked before usage. that functions receive the correct params and much more. This ensures that the code runs more stable and it also speeds up development. Lots of small mistakes can already be spotted by the editor. Code merges and refactors can be done much easier and with much more confidence, this is especially important for larger teams.

Flow vs Typescript, what are the differences?

Typescript was introduced by Microsoft in 2012. They struggled with huge amounts of internal javascript that wasn’t maintainable. They also wanted to use Javascript features that were only in a draft stage at this point, most notable, classes. To solve these problems they created Typescript. Flow was introduced 2 years later by Facebook. Their main motivation was to make their internal Javascript codebase more stable and reliable. Facebook had already experience creating a type system for a dynamic language, they had already created Hack to type PHP. The main differentiator to Typescript was that Flow was better at inferring types. So even without any extra type definitions, it was able to already find a lot of potential bugs. Since then Typescript has undoubtedly gained more community adoption. Looking at numbers like NPM downloads, it’s clear that Typescript has about 10 times higher adoption than Flow. The main reason is the difference in community support. Typescript updates are frequent and its documentation is excellent and very detailed. Flow’s documentation is very basic, and updates are rare and often break existing code. It seems like Facebook has forgotten about the community and only focuses on its internal use cases. Still, to this day Flow is way better at inferring types and it being enabled by default at a new react native repo, has given it some adoption.

When to use a typed language over plain javascript?

At DieProduktMacher we believe that the right amount of technology should be used at the right time. This means that every technology and procedure comes at a cost and that their benefits not always justify the cost. Same with typed languages. Javascript developers will encounter errors and syntax they’re not familiar with when starting with Typescript. This will initially slow them down. But the more people, time and money involved, the more Typescript will pay off. Ultimately it’s just practice and our experience shows that once typing is established, developers can’t imagine going back.


We've used Typescript for many projects at DieProduktMacher and it has helped us a lot. It made our code more readable, easier to work with and more stable!


Ähnliche Artikel

Ähnliche Artikel