Lay out the project

Lay out the project Let’s start out with a new directory. We’ll name it proj for now, but you can change it to whatever you want. mkdir proj cd proj To start, we’re going to structure our project in the following way: proj/ +- src/ +- built/ TypeScript files will start out in your src folder, run through the TypeScript compiler, and end up in built. Let’s scaffold this out: mkdir src mkdir built

jspm

jspm

iterator

Symbol.iterator A method that returns the default iterator for an object. Called by the semantics of the for-of statement.

Iterables

Iterables An object is deemed iterable if it has an implementation for the Symbol.iterator property. Some built-in types like Array, Map, Set, String, Int32Array, Uint32Array, etc. have their Symbol.iterator property already implemented. Symbol.iterator function on an object is responsible for returning the list of values to iterate on.

isConcatSpreadable

Symbol.isConcatSpreadable A Boolean value indicating that an object should be flatten to its array elements by Array.prototype.concat.

Intrinsic elements

Intrinsic elements Intrinsic elements are looked up on the special interface JSX.IntrinsicElements. By default, if this interface is not specified, then anything goes and intrinsic elements will not be type checked. However, if interface is present, then the name of the intrinsic element is looked up as a property on the JSX.IntrinsicElements interface. For example: declare namespace JSX { interface IntrinsicElements { foo: any } } <foo />; // ok <bar />; // error In the a

Intersection Types

Intersection Types An intersection type combines multiple types into one. This allows you to add together existing types to get a single type that has all the features you need. For example, Person & Serializable & Loggable is a Person and Serializable and Loggable. That means an object of this type will have all members of all three types. You will mostly see intersection types used for mixins and other concepts that don’t fit in the classic object-oriented mold. (There are a lot of th

Integrating with Build Tools

Integrating with Build Tools You might have some more build steps in your pipeline. Perhaps you concatenate something to each of your files. Each build tool is different, but we’ll do our best to cover the gist of things.

instanceof type guards

instanceof type guards If you’ve read about typeof type guards and are familiar with the instanceof operator in JavaScript, you probably have some idea of what this section is about. instanceof type guards are a way of narrowing types using their constructor function. For instance, let’s borrow our industrial string-padder example from earlier: interface Padder { getPaddingString(): string } class SpaceRepeatingPadder implements Padder { constructor(private numSpaces: number) { } getPad

Install typings for dependencies

Install typings for dependencies Angular 2 includes es6-shim for Promise support, but TypeScript still needs the types. Open a command prompt, then change directory to the app source: cd C:\Users\<you>\Documents\Visual Studio 2015\Projects\<app>\src\<app> npm install -g typings typings install --global dt~es6-shim