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
1 2 3 4 | greet({ greeting: "hello world" , duration: 4000 }); |
Declaration
Use an interface
to define a type with properties.
1 2 3 4 5 6 7 | interface GreetingSettings { greeting: string; duration?: number; color?: string; } declare function greet(setting: GreetingSettings): void; |
Please login to continue.