no-in-operator-on-built-in-collections
Do not use the in operator to test entries in built-in Map and Set collections.
Why
The in operator checks properties on the collection object and its prototype, while .has() checks stored entries. The similar spelling can silently test the wrong namespace.
Fix
Use collection.has(key) for entry membership. Use Reflect.has(collection, property) when prototype-aware property lookup or Proxy has behavior is intentional.
Examples
declare const cache: Map<string, object>;declare const key: string;if (key in cache) use(cache);declare const value: { id: string } | { slug: string };if ("id" in value) use(value.id);