Functions with overloads

Functions with overloads When a function has overloads, each overload in the source type must be matched by a compatible signature on the target type. This ensures that the target function can be called in all the same situations as the source function.

let declarations

let declarations By now you’ve figured out that var has some problems, which is precisely why let statements were introduced. Apart from the keyword used, let statements are written the same way var statements are. let hello = "Hello!"; The key difference is not in the syntax, but in the semantics, which we’ll now dive into.

Getting Stricter Checks

Getting Stricter Checks TypeScript comes with certain checks to give you more safety and analysis of your program. Once you’ve converted your codebase to TypeScript, you can start enabling these checks for greater safety.

Import a single export from a module

Import a single export from a module import { ZipCodeValidator } from "./ZipCodeValidator"; let myValidator = new ZipCodeValidator(); imports can also be renamed import { ZipCodeValidator as ZCV } from "./ZipCodeValidator"; let myValidator = new ZCV();

Readonly modifier

Readonly modifier You can make properties readonly by using the readonly keyword. Readonly properties must be initialized at their declaration or in the constructor. class Octopus { readonly name: string; readonly numberOfLegs: number = 8; constructor (theName: string) { this.name = theName; } } let dad = new Octopus("Man with the 8 strong legs"); dad.name = "Man with the 3-piece suit"; // error! name is readonly.

isConcatSpreadable

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

Destructuring

Destructuring Another ECMAScript 2015 feature that TypeScript has is destructuring. For a complete reference, see the article on the Mozilla Developer Network. In this section, we’ll give a short overview.

Initialize the project

Initialize the project Now we’ll turn this folder into an npm package. npm init You’ll be given a series of prompts. You can use the defaults except for your entry point. For your entry point, use ./dist/bundle.js. You can always go back and change these in the package.json file that’s been generated for you.

iterator

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

Using npm

Using npm npm install -g typescript@next