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

Create a page

Create a page Create a file in src named index.html: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Hello World!</title> </head> <body> <p id="greeting">Loading ...</p> <script src="bundle.js"></script> </body> </html> Now change main.ts to update the page: import { sayHello } from "./greet"; function showHello(divName: string, name: string) { const elt = document.getEl

Parameter Decorators

Parameter Decorators A Parameter Decorator is declared just before a parameter declaration. The parameter decorator is applied to the function for a class constructor or method declaration. A parameter decorator cannot be used in a declaration file, an overload, or in any other ambient context (such as in a declare class). The expression for the parameter decorator will be called as a function at runtime, with the following three arguments: Either the constructor function of the class for a sta

module-plugin.d.ts

// Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~] // Project: [~THE PROJECT NAME~] // Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]> /*~ This is the module plugin template file. You should rename it to index.d.ts *~ and place it in a folder with the same name as the module. *~ For example, if you were writing a file for "super-greeter", this *~ file should be 'super-greeter/index.d.ts' */ /*~ On this line, import the module which this module adds to */ impo

global.d.ts

// Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~] // Project: [~THE PROJECT NAME~] // Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]> /*~ If this library is callable (e.g. can be invoked as myLib(3)), *~ include those call signatures here. *~ Otherwise, delete this section. */ declare function myLib(a: string): string; declare function myLib(a: number): number; /*~ If you want the name of this library to be a valid type name, *~ you can do so here. *~ *~ F

Details

Details The "compilerOptions" property can be omitted, in which case the compiler’s defaults are used. See our full list of supported Compiler Options. The "files" property takes a list of relative or absolute file paths. The "include" and "exclude" properties take a list of glob-like file patterns. The supported glob wildcards are: * matches zero or more characters (excluding directory separators) ? matches any one character (excluding directory separators) **/ recursively matches any subdi

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

Classes

Classes Documentation You can create a greeter by instantiating the Greeter object, or create a customized greeter by extending from it. Code const myGreeter = new Greeter("hello, world"); myGreeter.greeting = "howdy"; myGreeter.showGreeting(); class SpecialGreeter extends Greeter { constructor() { super("Very special greetings"); } } Declaration Use declare class to describe a class or class-like object. Classes can have properties and methods as well as a constructor. declare clas

Set up the build

Set up the build

Object destructuring

Object destructuring You can also destructure objects: let o = { a: "foo", b: 12, c: "bar" } let {a, b} = o; This creates new variables a and b from o.a and o.b. Notice that you can skip c if you don’t need it. Like array destructuring, you can have assignment without declaration: ({a, b} = {a: "baz", b: 101}); Notice that we had to surround this statement with parentheses. JavaScript normally parses a { as the start of block.