Reusable Types (Interfaces)

Reusable Types (Interfaces)

Documentation

When specifying a greeting, you must pass a GreetingSettings object. This object has the following properties: - greeting: Mandatory string - duration: Optional length of time (in milliseconds) - color: Optional string, e.g. ‘#ff00ff’

Code

greet({
  greeting: "hello world",
  duration: 4000
});

Declaration

Use an interface to define a type with properties.

interface GreetingSettings {
  greeting: string;
  duration?: number;
  color?: string;
}

declare function greet(setting: GreetingSettings): void;
doc_TypeScript
2016-10-04 19:25:33
Comments
Leave a Comment

Please login to continue.