0 of 6 problems solved0%
4 of 6

Extend and Check

One interface can extend another to add more fields. An optional field may be missing, so your code should handle both cases. You will build a small contact shape and decide if we can send email.

interface Named {
  name: string;
}
interface WithPhone extends Named {
  phone?: string;
}

Write a pure function: look at the input and return a result without changing the input.

Your Task

Decide if a contact can be emailed.

  • Define interface Named { name: string }.
  • Define interface WithContact extends Named { email?: string }.
  • Implement canEmail(c: WithContact): boolean that returns true only when email exists and is not an empty string.
  • Do not mutate the input.