Command Palette

Search for a command to run...

Hectal
Phase 6: Classes and Object-Oriented TypeScript
TypeScript · Exercise 5 of 6 PreviousNext
Intermediate

A Fluent Email Builder

EmailBuilder has chainable methods and a subclass HtmlEmailBuilder adds bold. The chain new HtmlEmailBuilder().to(...).subject(...).bold(...) fails, because to and subject return the parent type, which forgets bold.

Fix the two return types so each method keeps the exact class it was called on. The program should print To: asha@x.in | Subject: Hello | <b>Welcome</b>. preview must stay read-only.

What Check tests

  1. Your code has no type errors
  2. The console prints the preview line
  3. A chain that starts with bold and goes back to to works
  4. preview cannot be assigned

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.