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:
interface 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:
let user: User = {name: 'john', age: 30};
Create three objects that implement the following interface:
interface Employee {
name: string,
age: number,
salaryday: number
}
Create three objects that implement the following interface:
interface Time {
hour: number,
minute: number,
second: number
}