Install TypeScript

Install TypeScript If your version of Visual Studio does not already have TypeScript, you can install it for Visual Studio 2015 or Visual Studio 2013. This quickstart uses Visual Studio 2015.

Install our dependencies

Install our dependencies First ensure TypeScript, Typings, and webpack are installed globally. npm install -g typescript typings webpack Webpack is a tool that will bundle your code and optionally all of its dependencies into a single .js file. Typings is a package manager for grabbing definition files. Let’s now add React and React-DOM as dependencies to your package.json file: npm install --save react react-dom Next, we’ll add development-time dependencies on ts-loader and source-map-loader

Install our dependencies

Install our dependencies Now we can use npm install to install packages. First install TypeScript and gulp globally. (You might need to start npm install commands in this guide with sudo if you’re on a Unix system.) npm install -g typescript gulp-cli Then install gulp and gulp-typescript in your project’s dev dependencies. Gulp-typescript is a gulp plugin for Typescript. npm install --save-dev gulp gulp-typescript

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

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.

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.

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/main.js. You can always go back and change these in the package.json file that’s been generated for you.

Inheritance

Inheritance In TypeScript, we can use common object-oriented patterns. Of course, one of the most fundamental patterns in class-based programming is being able to extend existing classes to create new ones using inheritance. Let’s take a look at an example: class Animal { name: string; constructor(theName: string) { this.name = theName; } move(distanceInMeters: number = 0) { console.log(`${this.name} moved ${distanceInMeters}m.`); } } class Snake extends Animal { constructor(name

Inferring the types

Inferring the types In playing with the example, you may notice that the TypeScript compiler can figure out the type if you have types on one side of the equation but not the other: // myAdd has the full function type let myAdd = function(x: number, y: number): number { return x + y; }; // The parameters 'x' and 'y' have the type number let myAdd: (baseValue:number, increment:number) => number = function(x, y) { return x + y; }; This is called “contextual typing”, a form of type inferen

Indexable Types

Indexable Types Similarly to how we can use interfaces to describe function types, we can also describe types that we can “index into” like a[10], or ageMap["daniel"]. Indexable types have an index signature that describes the types we can use to index into the object, along with the corresponding return types when indexing. Let’s take an example: interface StringArray { [index: number]: string; } let myArray: StringArray; myArray = ["Bob", "Fred"]; let myStr: string = myArray[0]; Above, w