Update tsconfig.json

Update tsconfig.json Now that Angular 2 and its dependencies are installed, we need to enable TypeScript’s experimental support for decorators and include the es6-shim typings. In the future decorators and ES6 will be the default and these settings will not be needed. Add "experimentalDecorators": true, "emitDecoratorMetadata": true to the "compilerOptions" section, and add "../typings/index.d.ts" to the "files" section. Finally, we need to add a new entry in "files" for another file, "./model.

The Impact of ES6 on Module Plugins

The Impact of ES6 on Module Plugins Some plugins add or modify top-level exports on existing modules. While this is legal in CommonJS and other loaders, ES6 modules are considered immutable and this pattern will not be possible. Because TypeScript is loader-agnostic, there is no compile-time enforcement of this policy, but developers intending to transition to an ES6 module loader should be aware of this.

Additional module resolution flags

Additional module resolution flags A project source layout sometimes does not match that of the output. Usually a set of build steps result in generating the final output. These include compiling .ts files into .js, and copying dependencies from different source locations to a single output location. The net result is that modules at runtime may have different names than the source files containing their definitions. Or module paths in the final output may not match their corresponding source f

Re-exports

Re-exports Often modules extend other modules, and partially expose some of their features. A re-export does not import it locally, or introduce a local variable. ParseIntBasedZipCodeValidator.ts export class ParseIntBasedZipCodeValidator { isAcceptable(s: string) { return s.length === 5 && parseInt(s).toString() === s; } } // Export original validator but rename it export {ZipCodeValidator as RegExpBasedZipCodeValidator} from "./ZipCodeValidator"; Optionally, a module can wra

Writing the function type

Writing the function type Now that we’ve typed the function, let’s write the full type of the function out by looking at the each piece of the function type. let myAdd: (x: number, y: number)=>number = function(x: number, y: number): number { return x+y; }; A function’s type has the same two parts: the type of the arguments and the return type. When writing out the whole function type, both parts are required. We write out the parameter types just like a parameter list, giving each parame

Ambient Modules

Ambient Modules In Node.js, most tasks are accomplished by loading one or more modules. We could define each module in its own .d.ts file with top-level export declarations, but it’s more convenient to write them as one larger .d.ts file. To do so, we use a construct similar to ambient namespaces, but we use the module keyword and the quoted name of the module which will be available to a later import. For example: node.d.ts (simplified excerpt) declare module "url" { export interface Url {

Consuming

Consuming From there you’ll be able to use lodash in your TypeScript code with no fuss. This works for both modules and global code. For example, once you’ve npm install-ed your type declarations, you can use imports and write import * as _ from "lodash"; _.padStart("Hello TypeScript!", 20, " "); or if you’re not using modules, you can just use the global variable _. _.padStart("Hello TypeScript!", 20, " ");

ToolsVersion

ToolsVersion The value of <TypeScriptToolsVersion>1.7</TypeScriptToolsVersion> property in the project file identifies the compiler version to use to build (1.7 in this example). This allows a project to build against the save versions of the compiler on different machines. If TypeScriptToolsVersion is not specified, the latest compiler version installed on the machine will be used to build. Users using newer versions of TS, will see a prompt to upgrade their project on first load.

Create a new project

Create a new project Choose File Choose New Project (Ctrl + Shift + N) Choose Visual C# Choose ASP.NET Web Application Choose ASP.NET 5 Empty Let’s uncheck “Host in the cloud” since we’re going to run this locally. Run the application and make sure that it works.

Global Variables

Global Variables Documentation The global variable foo contains the number of widgets present. Code console.log("Half the number of widgets is " + (foo / 2)); Declaration Use declare var to declare variables. If the variable is read-only, you can use declare const. You can also use declare let if the variable is block-scoped. /** The number of widgets present */ declare var foo: number;