4 ms·
Typescript has good reasons to default to Structural Typing as untagged union type are one of the most used types in typing js code and Nominal Typing does not
by afiori 2y ago
Typescript has good reasons to default to Structural Typing as untagged union type are one of the most used types in typing js code and Nominal Typing does not really have a good equivalent for them.
- mirekrusin 2y agoNominal typing with correct variance describes OO (classes, inheritance and rules governing it <<liskov substitution principles, L from SOLID>>). Structural typing is used for everything else in js. Flow does it correctly. Typescript treats everything as structurally typed. As a side note flow also has first class support for opaque types so no need to resort to branding hacks.
- int_19h 2y agoYou can do classes, inheritance, and LSP with structural typing just fine; look at OCaml.