, 9 tweets, 5 min read Read on Twitter
Here are some examples where Flow is great compared to TypeScript.

I was asked by many people after my tweet yesterday, so here you go.

I'm sure there are more examples. It is hard to tweet things out of context, but I've done my best to make small examples.

Thread...
Everything in TS is nullable by default. Yes I know about `strictNullChecks`, but not checking for null is one of the most common errors, and TypeScript's job is to catch this kind of thing.

This program is completely valid according to TS, but will crash immediately at runtime.
The same example in Flow will error as expected. Flow has optional types as well, which allow null or undefined, but require you to check before using them. Exactly what you want.
In TypeScript, untyped parameters have an implicit `any` type. In Flow, the type is inferred from the calls to that function.

In this example, TypeScript does not error, but the code will crash at runtime. Flow correctly errors, even with no annotation.
TypeScript's React support is also lacking. It does not correctly error based on element types, even with an annotation. For example, you may want to check that a child is a DOM element and not a custom component.

Flow correctly errors when passing the wrong element type.
TypeScript is inconsistent about allowing unknown properties in objects. It does not allow extra properties on object types by default (different from Flow), but doesn't always error properly.

Flow has both exact and normal object types, and errors properly.
String union types in TypeScript have very bad inference. In this example, destructuring with a default value requires a type cast to work correctly or it will just revert to a string type.

In flow this works correctly automatically.
Here are the overall takeaways:

* We don't need syntax noise in our code to get good type errors. The less we have to write and get the same errors the better.
* Safety first! Good defaults are important. A type system is about detecting errors early. Make this the default.
* The best technical solution doesn't always win. Sometimes, it's the things around it. Community, tool integrations, marketing, etc.
* I hope TS incorporates some of the ideas from Flow. Flow could also learn a thing or two from TS. Competition is good.
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Devon Govett
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!