Quiz · Narrowing · lesson 6 of 12Quiz — the in operatorHow does the in operator narrow a union of object types?[A]"swim" in animal checks at run time whether the object has that key, and tsc narrows on the result: the true branch keeps the members that declare swim, the false branch the rest. It works with plain object types, no class needed.[B]in narrows only the true branch: in the false branch the full union stays, because a missing key proves nothing about which member you hold, so after the if the object has to be checked again.[C]in works only inside tsc: it looks the key up in the declared types and is erased from the JavaScript, so at run time nothing checks the object, and both branches keep the full union of object types.[D]in narrows only class instances, because it looks for the key along the prototype chain of a class. With plain object types made with type, both branches keep the whole union, so you first have to add a shared field with a literal type.← BackThe in and instanceof checksNext →Discriminated unions