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

Write a simple Angular app in TypeScript

Write a simple Angular app in TypeScript First, change the code in app.ts to: import {Component} from "angular2/core" import {MyModel} from "./model" @Component({ selector: `my-app`, template: `<div>Hello from </div>` }) class MyApp { model = new MyModel(); getCompiler() { return this.model.compiler; } } Then add another TypeScript file in src named model.ts: export class MyModel { compiler = "TypeScript"; } And then another TypeScript file in src named main.ts: i

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

Test the resulting app

Test the resulting app gulp node dist/main.js The program should print “Hello from TypeScript!”.

Publish to @types

Publish to @types Packages on under the @types organization are published automatically from DefinitelyTyped using the types-publisher tool. To get your declarations published as an @types package, please submit a pull request to https://github.com/DefinitelyTyped/DefinitelyTyped. You can find more details in the contribution guidelines page.

Install ASP.NET Core and TypeScript

Install ASP.NET Core and TypeScript First, install ASP.NET Core if you need it. This quick-start guide uses Visual Studio, which means that you’ll need Visual Studio 2015 in order to use ASP.NET Core. Next, if your version of Visual Studio does not already have TypeScript, you can install it for Visual Studio 2015.

Block-scoping

Block-scoping When a variable is declared using let, it uses what some call lexical-scoping or block-scoping. Unlike variables declared with var whose scopes leak out to their containing function, block-scoped variables are not visible outside of their nearest containing block or for-loop. function f(input: boolean) { let a = 100; if (input) { // Still okay to reference 'a' let b = a + 1; return b; } // Error: 'b' doesn't exist here return b; } Here, we have two local v

Test

Test Run the project. You should see a message when you type in the input boxes:

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