Hacker News new | ask | show | jobs
by seanmcdirmid 2884 days ago
They aren’t the same though. Flow’s type system is nominal, typescript’s is structural, which is a huge language difference.
2 comments

Are they though? As a TypeScript user with very little Flow experience it seems like they are about the same:

https://flow.org/en/docs/lang/nominal-structural/

"For example, Flow uses structural typing for objects and functions, but nominal typing for classes." This statement also applies to TS.

Flow does have nominally typed Opaque Type Aliases[1], which are essentially newtypes from what I've gathered. However, you can build similar zero-cost newtypes in TypeScript using union types, casting and "unique symbol"[2].

[1] https://flow.org/en/docs/types/opaque-types/

[2] https://github.com/Microsoft/TypeScript/issues/4895#issuecom...

TypeScript seems to do structural typing for classes too: https://www.typescriptlang.org/play/#src=class%20Foo%20%7B%0...
i thought nominal typing was only for the classes?
That's true. Both Flow and TypeScript generally uses structural typing, but flow also has nominal typing for classes.