Type Checking with Intersections
This lesson explains how to identify a type using an intersection method.
Using a similar aspect of uniqueness as found in the structure before, it is possible to define a unique type using a generic class and intersection. The result is many new types that have a private, unique property which makes the shared type unique in turn, depending on its implementation.
The epitome of this pattern of intersections is currencies. A currency is a number and many numbers can be of a disparate currency. You want a single type for the money, but many currencies. At some point, you may need to verify that you are using the same currency, hence determining the type.
Get hands-on with 1200+ tech skills courses.