April 2018
Beginner
536 pages
13h 21m
English
Now that we have learned how to use the basic TypeScript building blocks individually, let's take a look at a final example in which we will use modules, classes, functions, and type annotations for each of these elements:
namespace geometry_demo { export interface Vector2DInterface { toArray(callback: (x: number[]) => void): void; length(): number; normalize(): void; } export class Vector2D implements Vector2DInterface { private _x: number; private _y: number; constructor(x: number, y: number) { this._x = x; this._y = y; } public toArray(callback: (x: number[]) => void): void { callback([this._x, this._y]); } public length(): number { return Math.sqrt( this._x * this._x + this._y * this._y ); } public normalize() ...