243 points · by Garbage · 9y ago · 97 comments
(That is, in terms of inertia, it seems like the community has decided on a winner)
flow started as "the better one of the two in theory" with better ideas, more strictness, way more expresiveness in its type system. But typescript took all these ideas, listened to the community and bridged the gap in features really fast, together with more stability, thus making flow pretty much obsolete.
typescript is way more stable. I can take a nightly or RC version of typescript and I know it's going to work better than flow which I tried several times and always let me down. If you don't trust a type system, it's hard to justify using it at all, apart from the documentation it provides to other devs.
These projects are complex, and I think only the typescript team invested enough to make it truly work.
100% agree, although I have to wonder, why don't you see that Typescript is NOT a type system you can depend on.
Fact of the matter is that Typescript has serious soundness issues and will always have. Those problems haven't disappeared.
What this translates to in practice is that Typescript annotations are little more than documentation. And it simply doesn't compare with any sane static language where the first line of defense is the compiler.
A static type system exists to prevent some classes of bugs and enable code completion.
However whenever "soundness" becomes a design goal, it enevitably usurps everything else (because it is an objective binary goal) and leads to languages that cease to value other things like simplicity or directness.
A type system can never catch all bugs and reliable programs ultimately depend on a human being understanding and verifying the code. The most important goal - if you value reliable programs - is that the code is intelligible to people.
This is true at the boundaries of your codebase, but if your application is complex enough, tsc is a life saver. Typescript saves me from bugs literally every day. Not to mention the benefits around tooling and refactoring.
Agreed that there are some big footguns with respect to soundness, though.
One of the big problems is that flow has far fewer definition files available. Most projects don't want to support two separate type specs. Even if it didn't provide 100% compatibility, having something take you 90% of the way there would be a big improvement.
But I'm still betting on flow. I like that it's supported by babel and it generally seems to be better at helping you catch bugs. @thejameskyle recently tweeted [0] a short snippet showing a great example showcasing flow.
[0] https://twitter.com/thejameskyle/status/868148120504356864
function getOptions() { return { num: 42, str: "val" }; }
var __options__ = getOptions();
type Options = typeof __options__;
var options: Options = {
^^^^ Type is not assignable
num: "hi",
str: 42
};But in your TS example, the code would execute. Not in the Flow example, where it's just an annotation.
There are hacks and other approaches, documented here:
declare var $: any;
$( "element" ).compiler.leaves.you.alone
declare module 'themodule' { var mock: any; export default mock; }
But unless the lib doesn't propagate through your code at all, it pays of to give it proper typings.
On the other hand, I'll take ts over js any day.
(In the old days, type systems were just purely about correctness, so soundness was key, but those days are long past us, we depend on type systems for many different things now)
An actual sound type system built on top of regular JS would be unusable - you'd have to disallow almost everything. The language is too "dynamic" to become properly sound.
(the weekly view is easiest to parse)
Looks like flow downloads have been declining week-on-week for the past 6 weeks.
Note that flow is likely underrepresented, since many people install it with brew (or apt-get, or whatever).
This project has not been super active recently (because most of the people involved are working more on VS Code version of Ionide), but doing an Atom plugin with F# was quite nice :-). I linked the above file, because using nice `async` support and agent-based programming works really nicely in the editor context.
I made a small simple demo here: https://www.typescriptlang.org/play/index.html#src=const%20e...
Note: Click Options and enable all the settings. Typescript works best in strict mode, but it seems options arn't including in sharing via url.
In fact to set a global value (ex: window.Foo) requires a bit of extra work to instruct the type check that your new property is not errant.
Unless, of course, you're implying it converts javascript into a strongly typed language, which would be amazing.
1 + '1' is authorized.
1 + [] is not.
If I wanted a typed language, I would use a typed language. JS has a lot of benefits. Being able to use JS to make native-ish apps has it's place. Being able to use typed JS to make native-ish apps probably means you should be using a different language.
If you're doing server-side development, then you have a million languages to choose from. If you're developing within the context of a browser engine, then the choice was made for you over 20 years ago.
If you like that choice, then great. If you don't, then you transpile. Either way, it's silly to act as if there's a contradiction here.