User story

The user is expected to increment or decrement a counter from the click of a button, basically, a counter that's initialized to 0an increment button to increment by 1, and a decrement button to decrement by 1.

Rather than littering our code with DOM manipulations and event logic, we can organize them into classes. After all, that's why classes exist:

// Code 2.4.tsclass DOM {  private _incBtn: HTMLElement;  private _decBtn: HTMLElement;  private _counter: HTMLElement;  constructor() {    this._incBtn = this._getDOMElement('#incBtn');    this._decBtn = this._getDOMElement('#decBtn');    this._counter = this._getDOMElement('#counter');  }    public _getDOMElement (selector: string) : HTMLElement { return document.querySelector(selector) as HTMLElement; ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.