Type Checking and Interface with a Discriminator

In this lesson, you will follow-up on the literal type and how it can be used to discriminate a type.

Checking type with literal

In the literal type lesson, you saw that a literal type can be used to differentiate different types. It means that you may have a function that takes a union of several types that you would like to figure out which type is being passed, to accomplish something specific to that type. You also saw the pattern of branding in a type alias that is using a discriminator in one of its patterns. As a reminder, here is an example with lines 2 and 8 that has two string literals.

Get hands-on with 1200+ tech skills courses.