Book Image

TypeScript Essentials

By : Christopher Nance
Book Image

TypeScript Essentials

By: Christopher Nance

Overview of this book

Table of Contents (15 chapters)

Interfaces


Interfaces are a key piece of creating large-scale software applications. They are a way of representing complex types about any object. Despite their usefulness they have absolutely no runtime consequences because JavaScript does not include any sort of runtime type checking. Interfaces are analyzed at compile time and then omitted from the resulting JavaScript. Interfaces create a contract for developers to use when developing new objects or writing methods to interact with existing ones. Interfaces are named types that contain a list of members. Let's look at an example of an interface:

interface IPoint {
    x: number;
    y: number;
}

As you can see we use the interface keyword to start the interface declaration. Then we give the interface a name that we can easily reference from our code.

Note

Interfaces can be named anything, for example, foo or bar, however, a simple naming convention will improve the readability of the code. Throughout this book, interfaces will be given...