Book Image

TypeScript Blueprints

By : Ivo Gabe de Wolff
Book Image

TypeScript Blueprints

By: Ivo Gabe de Wolff

Overview of this book

TypeScript is the future of JavaScript. Having been designed for the development of large applications, it is now being widely incorporated in cutting-edge projects such as Angular 2. Adopting TypeScript results in more robust software - software that is more scalable and performant. It's scale and performance that lies at the heart of every project that features in this book. The lessons learned throughout this book will arm you with everything you need to build some truly amazing projects. You'll build a complete single page app with Angular 2, create a neat mobile app using NativeScript, and even build a Pac Man game with TypeScript. As if fun wasn't enough, you'll also find out how to migrate your legacy codebase from JavaScript to TypeScript. This book isn't just for developers who want to learn - it's for developers who want to develop. So dive in and get started on these TypeScript projects.
Table of Contents (16 chapters)
TypeScript Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Using modules


We will use modules in all applications in this book. Modules (also called external modules and ES2015 modules) are a concept of separating code in multiple files. Every file is a module. Within these modules, you can use variables, functions, and classes (members) exported by other modules and you can make some members visible for other modules. To use other modules, you must import them, and to make members visible, you need to export them. The following example will show some basic usage:

// x.ts 
import { one, add, Lorem } from './y'; 
console.log(add(one, 2)); 
 
var lorem = new Lorem(); 
console.log(lorem.name); 
 
// y.ts 
export var one = 1; 
export function add(a: number, b: number) { 
  return a + b; 
} 
export class Lorem { 
  name = "ipsum"; 
} 

You can export declarations by prefixing them with the export keyword or by prefixing them with export default. A default export should be imported...