Book Image

TypeScript Essentials

By : Christopher Nance
Book Image

TypeScript Essentials

By: Christopher Nance

Overview of this book

Table of Contents (15 chapters)

The shapes

In keeping with the principles that we learned in the previous chapter, we will need a variety of different types to perform different tasks within our application. We will need a representation of what shapes are, how to draw them, something to interact with the user interface, and somewhere to maintain the list of objects to be drawn.

Basic shapes

The first thing we need is a set of classes that will represent the different shapes that we eventually intend on drawing. These objects should be kept separate from the drawing logic that we will implement later. The first thing we need to do is create an abstraction for each of the shapes we intend on representing. This abstraction will allow us to easily extend object types or swap certain objects for others as requirements change. The abstraction is as follows:

interface IPoint {
    x: number;
    y: number;
interface IShape {
interface IRectangle extends IShape {
    height: number;
    width: number;
    resize(height: number...