3 ms·
They aren’t the same though. Flow’s type system is nominal, typescript’s is structural, which is a huge language difference.
by seanmcdirmid 8y ago
They aren’t the same though. Flow’s type system is nominal, typescript’s is structural, which is a huge language difference.
- merkaloid 8y agoi thought nominal typing was only for the classes?
- sverrejoh 8y agoThat's true. Both Flow and TypeScript generally uses structural typing, but flow also has nominal typing for classes.
- paavohtl 8y agoAre 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/ 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/ https://flow.org/en/docs/types/opaque-types/ [2] https://github.com/Microsoft/TypeScript/issues/4895#issuecomment-398821503 https://github.com/Microsoft/TypeScript/issues/4895#issuecom...
- rictic 8y agoTypeScript seems to do structural typing for classes too: https://www.typescriptlang.org/play/#src=class%20Foo%20%7B%0D%0A%20%20field%3A%20string%20%3D%20''%3B%0D%0A%7D%0D%0A%0D%0Aclass%20Bar%20%7B%0D%0A%20%20field%3A%20string%20%3D%20''%3B%0D%0A%7D%0D%0A%0D%0Alet%20foo%3A%20Foo%3B%0D%0Afoo%20%3D%20new%20Foo()%3B%0D%0Afoo%20%3D%20new%20Bar()%3B%0D%0A https://www.typescriptlang.org/play/#src=class%20Foo%20%7B%0...