How to Narrow a Type with the in Operator
This lesson will look at how to use the in operator to narrow a type.
We'll cover the following
The in
operator explained
The in
operator can narrow a type from a union. The left part of the operand is a string or a string literal. The right part is a union type. The result is a Boolean
that returns true
if the union contains the string and false
if it doesn’t.
Usage of the in
operator explained
Get hands-on with 1400+ tech skills courses.