Skip to content

Instantly share code, notes, and snippets.

@icholy
Created March 10, 2015 15:42
Show Gist options
  • Save icholy/8c48677d37afcc6e2404 to your computer and use it in GitHub Desktop.
Save icholy/8c48677d37afcc6e2404 to your computer and use it in GitHub Desktop.

Prefix all interfaces with Foo

interface IFooOptions {}

class Foo {
  constructor(options: IFooOptions) {}
}

// usage
var foo = new Foo({});

Create a Foo module

module Foo {
  export interface IOptions {
    // ...
  }

  export class Foo {
    constructor(options: IOptions) {}
  }
}

// usage
var foo = new Foo.Foo({});

Create module Foo with factory function

module Foo {
  export interface IOptions {
    // ...
  }

  export class Foo {
    constructor(options: IOptions) {}
  }

  export function create(options: IOptions): Foo {
    return new Foo(options);
  }
}

// usage
var foo = Foo.create({});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment