[0] https://flow.org/try/#0C4TwDgpgBAggxsAlgewHZQLwCgq6gHygG8oBr...
function x(y: {
foo: number,
bar?: number
}) {}
const y = {
foo: 1,
baar: 2, // typo
}
x(y)
The above is caught in Flow when exact types are enabled but not in TS.TS issue https://github.com/microsoft/TypeScript/issues/12936
TS has a concept of "freshness" which catches some of these mistakes when you construct y right in the arguments of x, but it gets easily broken by accident and without a warning.
2. Nominal types, so you can have for example "Id" type that is a number but not to be mixed with other numbers, you can't just call a function that expects an Id with literal 42. Classes are nominal too, which I think is a solid choise.
3. Type variance & related safeguards
function x(y: {
foo: string | number
}) {
y.foo = 1
}
const y: {
foo: string
} = {foo: 'a'}
x(y)
y.foo.toUpperCase()
Caught by Flow but not TS.4. Local call site type inference of function argument types, so you can have some helper functions within a file that you don't need to explicitly annotate, and Flow will happily infer types based on how you call it.
5. Performance has gotten prerty good with recent versions, to the point where I suspect it's faster than TS. I don't have any hard data on this though.
Even though in many many ways Flow is worse than TS, we have still stuck with it, and that's only like 80% because it'd be s huge undertaking to make the switch. 20% is because some of these features are actually nice :)
If you add nominal types, some people might expect them to be boxed, and thus be able to reflect on types at runtime. So I assume that TypeScript maintainers have made a design decision that users should have to “self-box” nominal types.
Structural typing is one of the best features of TS in my opinion, I like it in general but it's a better fit for JS ecosystem.
This is far from perfect, but when you're working with very tricky code and want to be sure, you at least have the option
I think that's it these days. Flow used to have (slightly) more features but now TS has way more already and even more to come. The Flow people moved on to Recript, or whatever name they call it these days.