Skip to content

Latest commit

 

History

History
85 lines (55 loc) · 1.37 KB

examples.md

File metadata and controls

85 lines (55 loc) · 1.37 KB

Examples

Here are some examples you can use as a model when writing your own type definitions.

Single function

Exposing a single function.

declare function domready (...): any;

export = domready

Function with overloads.

declare function xtend <A> (a: A): A;
declare function xtend <A, B> (a: A, b: B): A & B;
export = xtend;

Utility library

Exposing a collection of utility functions and classes.

declare module JsDiff {
  class Diff {}
  function diffChars(): any;
}

export = JsDiff;

Function + utility

Exposing a function, with utility methods.

declare function tape (): any;

declare namespace tape {
  export function skip (): any;
}

export = tape;

Exporting class + static methods + utility (ES6)

declare class Promise <R> {
  static resolve(): Promise<void>;
}

declare module Promise {
  export interface SpreadOption {}
  export function setScheduler (): any;
}

export = Promise;

Named export (ES6)

Export directly using ES6 semantics without a module or namespace.

export function valid(): any;

export class SemVer {}