// Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~] // Project: [~THE PROJECT NAME~] // Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]>
/*~ This is the global-modifying module 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' */
/*~ Note: If your global-modifying module is callable or constructable, you'll *~ need to combine the patterns here with those in the module-class or module-function *~ template files */ declareglobal { /*~ Here, declare things that go in the global namespace, or augment *~ existing declarations in the global namespace */ interfaceString { fancyFormat(opts: StringFormatOptions): string; } }
/*~ If your module exports types or values, write them as usual */ exportinterfaceStringFormatOptions { fancinessLevel: number; }
/*~ For example, declaring a method on the module (in addition to its global side effects) */ exportfunctiondoSomething(): void;
/*~ If your module exports nothing, you'll need this line. Otherwise, delete it */ export { };
// Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~] // Project: [~THE PROJECT NAME~] // Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]>
/*~ This template shows how to write a global plugin. */
/*~ Write a declaration for the original type and add new members. *~ For example, this adds a 'toBinaryString' method with to overloads to *~ the built-in number type. */ interfaceNumber { toBinaryString(opts?: MyLibrary.BinaryFormatOptions): string; toBinaryString(callback: MyLibrary.BinaryFormatCallback, opts?: MyLibrary.BinaryFormatOptions): string; }
/*~ If you need to declare several types, place them inside a namespace *~ to avoid adding too many things to the global namespace. */ declarenamespaceMyLibrary { typeBinaryFormatCallback = (n: number) =>string; interfaceBinaryFormatOptions { prefix?: string; padding: number; } }
// 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. */ declarefunctionmyLib(a: string): string; declarefunctionmyLib(a: number): number;
/*~ If you want the name of this library to be a valid type name, *~ you can do so here. *~ *~ For example, this allows us to write 'var x: myLib'; *~ Be sure this actually makes sense! If it doesn't, just *~ delete this declaration and add types inside the namespace below. */ interface myLib { name: string; length: number; extras?: string[]; }
/*~ If your library has properties exposed on a global variable, *~ place them here. *~ You should also place types (interfaces and type alias) here. */ declarenamespacemyLib { //~ We can write 'myLib.timeout = 50;' lettimeout: number;
//~ We can access 'myLib.version', but not change it constversion: string;
//~ There's some class we can create via 'let c = new myLib.Cat(42)' //~ Or reference e.g. 'function f(c: myLib.Cat) { ... } classCat { constructor(n: number);
//~ We can read 'c.age' from a 'Cat' instance readonlyage: number;
//~ We can invoke 'c.purr()' from a 'Cat' instance purr(): void; }
//~ We can declare a variable as //~ 'var s: myLib.CatSettings = { weight: 5, name: "Maru" };' interfaceCatSettings { weight: number; name: string; tailLength?: number; }
//~ We can write 'const v: myLib.VetID = 42;' //~ or 'const v: myLib.VetID = "bob";' typeVetID = string | number;
//~ We can invoke 'myLib.checkCat(c)' or 'myLib.checkCat(c, v);' functioncheckCat(c: Cat, s?: VetID); }
// 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 template file for class modules. *~ 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' */
/*~ Note that ES6 modules cannot directly export class objects. *~ This file should be imported using the CommonJS-style: *~ import x = require('someLibrary'); *~ *~ Refer to the documentation to understand common *~ workarounds for this limitation of ES6 modules. */
/*~ If this module is a UMD module that exposes a global variable 'myClassLib' when *~ loaded outside a module loader environment, declare that global here. *~ Otherwise, delete this declaration. */ exportasnamespacemyClassLib;
/*~ This declaration specifies that the class constructor function *~ is the exported object from the file */ export = MyClass;
/*~ Write your module's methods and properties in this class */ declareclassMyClass { constructor(someParam?: string);
/*~ If you want to expose types from your module as well, you can *~ place them in this block. */ declarenamespaceMyClass { exportinterfaceMyClassMethodOptions { width?: number; height?: number; } }
// 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 template file for function modules. *~ 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' */
/*~ Note that ES6 modules cannot directly export callable functions. *~ This file should be imported using the CommonJS-style: *~ import x = require('someLibrary'); *~ *~ Refer to the documentation to understand common *~ workarounds for this limitation of ES6 modules. */
/*~ If this module is a UMD module that exposes a global variable 'myFuncLib' when *~ loaded outside a module loader environment, declare that global here. *~ Otherwise, delete this declaration. */ exportasnamespacemyFuncLib;
/*~ This declaration specifies that the function *~ is the exported object from the file */ export = MyFunction;
/*~ This example shows how to have multiple overloads for your function */ declarefunctionMyFunction(name: string): MyFunction.NamedReturnType; declarefunctionMyFunction(length: number): MyFunction.LengthReturnType;
/*~ If you want to expose types from your module as well, you can *~ place them in this block. Often you will want to describe the *~ shape of the return type of the function; that type should *~ be declared in here, as this example shows. */ declarenamespaceMyFunction { exportinterfaceLengthReturnType { width: number; height: number; } exportinterfaceNamedReturnType { firstName: string; lastName: string; }
/*~ If the module also has properties, declare them here. For example, *~ this declaration says that this code is legal: *~ import f = require('myFuncLibrary'); *~ console.log(f.defaultName); */ exportconstdefaultName: string; exportletdefaultLength: number; }
// 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 */ import * as m from'someModule';
/*~ You can also import other modules if needed */ import * as other from'anotherModule';
/*~ Here, declare the same module as the one you imported above */ declaremodule'someModule' { /*~ Inside, add new function, classes, or variables. You can use *~ unexported types from the original module if needed. */ exportfunctiontheNewMethod(x: m.foo): other.bar;
/*~ You can also add new properties to existing interfaces from *~ the original module by writing interface augmentations */ exportinterfaceSomeModuleOptions { someModuleSetting?: string; }
/*~ New types can also be declared and will appear as if they *~ are in the original module */ exportinterfaceMyModulePluginOptions { size: number; } }
// 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 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' */
/*~ If this module is a UMD module that exposes a global variable 'myLib' when *~ loaded outside a module loader environment, declare that global here. *~ Otherwise, delete this declaration. */ exportasnamespacemyLib;
/*~ If this module has methods, declare them as functions like so. */ exportfunctionmyMethod(a: string): string; exportfunctionmyOtherMethod(a: number): number;
/*~ You can declare types that are available via importing the module */ exportinterface someType { name: string; length: number; extras?: string[]; }
/*~ You can declare properties of the module using const, let, or var */ exportconstmyField: number;
/*~ If there are types, properties, or methods inside dotted names *~ of the module, declare them inside a 'namespace'. */ exportnamespacesubProp { /*~ For example, given this definition, someone could write: *~ import { subProp } from 'yourModule'; *~ subProp.foo(); *~ or *~ import * as yourMod from 'yourModule'; *~ yourMod.subProp.foo(); */ exportfunctionfoo(): void; }