The JavaScript in operator checks whether an object has a named property, including a property inherited from its prototype. In TypeScript, this test can act as a type guard for union-shaped objects. section 10.2.6
Distinguishing products from people
For a (Product | Person)[] union, test for a property unique to one shape: if ("city" in item), TypeScript narrows item to Person; otherwise, it treats item as Product. The branches can then safely access city or price. section 10.2.6
Build reliable membership checks by following these constraints:
- Choose a property included in one shape but not the other, such as city for Person or price for Product. section 10.2.6
- Avoid inaccurate tests that do not definitively distinguish the possible object types. section 10.2.6







