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.

<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.

Array destructuring

Array destructuring The simplest form of destructuring is array destructuring assignment: let input = [1, 2]; let [first, second] = input; console.log(first); // outputs 1 console.log(second); // outputs 2 This creates two new variables named first and second. This is equivalent to using indexing, but is much more convenient: first = input[0]; second = input[1]; Destructuring works with already-declared variables as well: // swap variables [first, second] = [second, first]; And with paramete

Weeding out Errors

Weeding out Errors Like we mentioned, it’s not unexpected to get error messages after conversion. The important thing is to actually go one by one through these and decide how to deal with the errors. Often these will be legitimate bugs, but sometimes you’ll have to explain what you’re trying to do a little better to TypeScript.

Namespacing

Namespacing As we add more validators, we’re going to want to have some kind of organization scheme so that we can keep track of our types and not worry about name collisions with other objects. Instead of putting lots of different names into the global namespace, let’s wrap up our objects into a namespace. In this example, we’ll move all validator-related entities into a namespace called Validation. Because we want the interfaces and classes here to be visible outside the namespace, we preface