4 ms·
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/
by paavohtl 8y ago
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/ 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...