Interfaces in TypeScript

A more advanced version of object typing in TypeScript are interfaces. They allow you to create new data types that describe the structure of objects.

Interfaces are created using the interface keyword, followed by the name of the interface (written with a capital letter), and then the structure of the object is described in curly brackets.

Let's make an interface for example that describes the structure of an object with a user:

typescriptinterface User {
  name: string,
  age: number
}

Now let's create an object that implements this interface. To do this, we'll specify the name of our interface as the object type:

typescriptlet user: User = {name: 'john', age: 30};
Задание 1

Create three objects that implement the following interface:

typescriptinterface Employee {
  name: string,
  age: number,
  salaryday: number
}
Задание 2

Create three objects that implement the following interface:

typescriptinterface Time {
  hour: number,
  minute: number,
  second: number
}