JS Built-ins
TypeScriptbeginner

Interface β€” with Method

πŸ“– Usage Example
interface Counter { count: number; increment(): void; decrement(): void }
const c = createCounter()
c.increment()
c.count   // β†’ 1

Interface method signatures declare both the function shape and ensure objects provide implementations.

Interfaces with Methods

Interfaces can include method signatures. Implement an object that satisfies the interface.

Challenge: Implement createPrintable(label, value) returning an object with a toString() method.

createPrintable('Name', 'Alice').toString()  // β†’ 'Name: Alice'
πŸ’‘ Hints (1)
  • β€’ Template literals automatically call toString() on values.