O'Reilly logo

TypeScript Blueprints by Ivo Gabe de Wolff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Quick example

The following example code shows some basic TypeScript usage. If you understand this code, you have enough knowledge for the next chapters. This example code creates an input box in which you can enter a name. When you click on the button, you will see a personalized greeting:

class Hello { private element: HTMLDivElement; private elementInput: HTMLInputElement; private elementText: HTMLDivElement; constructor(defaultName: string) { this.element = document.createElement("div"); this.elementInput = document.createElement("input"); this.elementText = document.createElement("div"); const elementButton = document.createElement("button"); elementButton.textContent = "Greet"; this.element.appendChild(this.elementInput); this.element.appendChild(elementButton); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required