Using --noResolve

Using --noResolve Normally the compiler will attempt to resolve all module imports before it starts the compilation process. Every time it successfully resolves an import to a file, the file is added to the set of files the compiler will process later on. The --noResolve compiler options instructs the compiler not to “add” any files to the compilation that were not passed on the command line. It will still try to resolve the module to files, but if the file as not specified, it will not be inc

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, " ");

Templates

global-modifying-module.d.ts global-plugin.d.ts global.d.ts module-class.d.ts module-function.d.ts module-plugin.d.ts module.d.ts

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

TypeScript 1.1

Performance Improvements The 1.1 compiler is typically around 4x faster than any previous release. See this blog post for some impressive charts. Better Module Visibility Rules TypeScript now only strictly enforces the visibility of types in modules if the --declaration flag is provided. This is very useful for Angular scenarios, for example: module MyControllers { interface ZooScope extends ng.IScope { animals: Animal[]; } export class ZooController { // Used to be an error (cannot e

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.

Parameter properties

Parameter properties In our last example, we had to declare a readonly member name and a constructor parameter theName in the Octopus class, and we then immediately set name to theName. This turns out to be a very common practice. Parameter properties let you create and initialize a member in one place. Here’s a further revision of the previous Octopus class using a parameter property: class Octopus { readonly numberOfLegs: number = 8; constructor(readonly name: string) { } } Notice how

Mappings

Mappings Compiler Option MSBuild Property Name Allowed Values --allowJs Not supported in MSBuild --allowSyntheticDefaultImports TypeScriptAllowSyntheticDefaultImports boolean --allowUnreachableCode TypeScriptAllowUnreachableCode boolean --allowUnusedLabels TypeScriptAllowUnusedLabels boolean --baseUrl TypeScriptBaseUrl File path --charset TypeScriptCharset --declaration TypeScriptGeneratesDeclarations boolean --declarationDir TypeScriptDeclarationDir File path --diagnostics Not supported in

Compiler Options

Compiler Options Option Type Default Description --allowJs boolean true Allow JavaScript files to be compiled. --allowSyntheticDefaultImports boolean module === "system" Allow default imports from modules with no default export. This does not affect code emit, just typechecking. --allowUnreachableCode boolean false Do not report errors on unreachable code. --allowUnusedLabels boolean false Do not report errors on unused labels. --baseUrl string Base directory to resolve non-relative module na

Modular Libraries

Modular Libraries Some libraries only work in a module loader environment. For example, because express only works in Node.js and must be loaded using the CommonJS require function. ECMAScript 2015 (also known as ES2015, ECMAScript 6, and ES6), CommonJS, and RequireJS have similar notions of importing a module. In JavaScript CommonJS (Node.js), for example, you would write var fs = require("fs"); In TypeScript or ES6, the import keyword serves the same purpose: import fs = require("fs"); You’