TypeScript 1.6

JSX support JSX is an embeddable XML-like syntax. It is meant to be transformed into valid JavaScript, but the semantics of that transformation are implementation-specific. JSX came to popularity with the React library but has since seen other applications. TypeScript 1.6 supports embedding, type checking, and optionally compiling JSX directly into JavaScript. New .tsx file extension and as operator TypeScript 1.6 introduces a new .tsx file extension. This extension does two things: it enables

Dependencies on UMD libraries

Dependencies on UMD libraries

Templates

Templates In Templates you’ll find a number of declaration files that serve as a useful starting point when writing a new file. Refer to the documentation in Library Structures to figure out which template file to use.

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

<reference no-default-lib="true"/>

/// <reference no-default-lib="true"/> This directive marks a file as a default library. You will see this comment at the top of lib.d.ts and its different variants. This directive instructs the compiler to not include the default library (i.e. lib.d.ts) in the compilation. The impact here is similar to passing --noLib on the command line. Also note that when passing --skipDefaultLibCheck, the compiler will only skip checking files with /// <reference no-default-lib="true"/>.

Deep Dive

Deep Dive For seasoned authors interested in the underlying mechanics of how declaration files work, the Deep Dive section explains many advanced concepts in declaration writing, and shows how to leverage these concepts to create cleaner and more intuitive declaration files.

for...of statements

for..of statements for..of loops over an iterable object, invoking the Symbol.iterator property on the object. Here is a simple for..of loop on an array: let someArray = [1, "string", false]; for (let entry of someArray) { console.log(entry); // 1, "string", false }

Sections

Sections The guide is broken down into the following sections.

Install our build dependencies

Install our build dependencies First ensure TypeScript and Typings are installed globally. npm install -g typescript typings You obviously know about TypeScript, but you might not know about Typings. Typings is a package manager for grabbing definition files. We’ll now use Typings to grab declaration files for Knockout: typings install --global --save dt~knockout The --global flag will tell Typings to grab any declaration files from DefinitelyTyped, a repository of community-authored .d.ts fi

Overloaded Functions

Overloaded Functions Documentation The getWidget function accepts a number and returns a Widget, or accepts a string and returns a Widget array. Code let x: Widget = getWidget(43); let arr: Widget[] = getWidget("all of them"); Declaration declare function getWidget(n: number): Widget; declare function getWidget(s: string): Widget[];