0 of 6 problems solved0%
2 of 6

Exclusive Contact Kind

Object unions can be exclusive when each variant has different keys. The in operator narrows by checking for a property at runtime. If 'email' in c is true, you have the email variant; otherwise, you might have the phone variant.

function isEmail(c: { email: string } | { phone: string }) {
  return "email" in c;
}

Return a boolean so callers can branch as needed.

Your Task

Detect whether a contact carries an email.

  • Define type EmailContact = { email: string } and type PhoneContact = { phone: string }.
  • Define type Contact = EmailContact | PhoneContact.
  • Implement function hasEmail(c: Contact): boolean using the in operator.
  • Keep the function pure (no mutation).