DEV Community

Discussion on: Tossing TypeScript

 
blueharborbrandon profile image
BlueHarborBrandon • Edited

Conceptually, perhaps, but not in practice. That is, you may be able to identify sets within the type system in other languages, but it's fundamental to TypeScript.

In C#, for example, objects must claim exactly one class that must be tightly associated with the object in order to use it. Trying to say it's a type outside of the inheritance chain results in an error. Or, to put it differently, one value at runtime has a small, rigid set of types it fits - unlike the number 2, which belongs to an infinite number of sets. In short, values have types, rather than types having values.

But in TypeScript, types are modeled as sets essentially from the ground up. Just like in math, you can say "this set contains every value with these properties", or "this set contains precisely these values", or "this set is the union/intersection of these other sets". Understanding fundamental set theory helps you think about types in TS in a way that it doesn't with C# or many other languages.