Organizing Types

Organizing Types

Documentation

The greeter object can log to a file or display an alert. You can provide LogOptions to .log(...) and alert options to .alert(...)

Code

const g = new Greeter("Hello");
g.log({ verbose: true });
g.alert({ modal: false, title: "Current Greeting" });

Declaration

Use namespaces to organize types.

declare namespace GreetingLib {
  interface LogOptions {
    verbose?: boolean;
  }
  interface AlertOptions {
    modal: boolean;
    title?: string;
    color?: string;
  }
}

You can also created nested namespaces in one declaration:

declare namespace GreetingLib.Options {
  // Refer to via GreetingLib.Options.Log
  interface Log {
    verbose?: boolean;
  }
  interface Alert {
    modal: boolean;
    title?: string;
    color?: string;
  }
}
doc_TypeScript
2016-10-04 19:25:29
Comments
Leave a Comment

Please login to continue.