Ambient enums

Ambient enums Ambient enums are used to describe the shape of already existing enum types. declare enum Enum { A = 1, B, C = 2 } One important difference between ambient and non-ambient enums is that, in regular enums, members that don’t have an initializer are considered constant members. For non-const ambient enums member that does not have initializer is considered computed.

Aliases

Aliases Another way that you can simplify working with of namespaces is to use import q = x.y.z to create shorter names for commonly-used objects. Not to be confused with the import x = require("name") syntax used to load modules, this syntax simply creates an alias for the specified symbol. You can use these sorts of imports (commonly referred to as aliases) for any kind of identifier, including objects created from module imports. namespace Shapes { export namespace Polygons { export cl

Advanced Combinations

Advanced Combinations Some kinds of declarations can be combined across multiple declarations. For example, class C { } and interface C { } can co-exist and both contribute properties to the C types. This is legal as long as it does not create a conflict. A general rule of thumb is that values always conflict with other values of the same name unless they are declared as namespaces, types will conflict if they are declared with a type alias declaration (type s = string), and namespaces never co

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

Add TypeScript code

Add TypeScript code Right click on src and click New Item. Then choose TypeScript File and name the file app.ts.

Add TypeScript code

Add TypeScript code Right click on scripts and click New Item. Then choose TypeScript File (it may be in the .NET Core section) and name the file app.ts.

Add TypeScript

Add TypeScript The next step is to add a folder for TypeScript. We’ll just call it src.

Add TypeScript

Add TypeScript The next step is to add a folder for TypeScript. We’ll just call it scripts.

Add NPM dependencies

Add NPM dependencies Add the following "dependencies" to package.json to install Angular 2 and SystemJS: "dependencies": { "angular2": "2.0.0-beta.11", "systemjs": "0.19.24", },

Add modules to the code

Add modules to the code Before we get to Browserify, let’s build our code out and add modules to the mix. This is the structure you’re more likely to use for a real app. Create a file called src/greet.ts: export function sayHello(name: string) { return `Hello from ${name}`; } Now change the code in src/main.ts to import sayHello from greet.ts: import { sayHello } from "./greet"; console.log(sayHello("TypeScript")); Finally, add src/greet.ts to tsconfig.json: { "files": [ "src/main.ts