in operator

The JavaScript operator "key" in obj, which checks whether an object has a property and lets TypeScript narrow a union by it.

In more detail

It works when union members have no common tag: "exp" in token picks out the JSON Web Token variant. It never throws for a missing property, but the left side must be an object, so check for null first.

Related terms

Taught in

References