Typescript - Interface (Implement)

About

Data Type - Interface (Abstract Type) in Typescript

An interface is a type that describes objects

Implement

In TypeScript, two types are compatible if their internal structure is compatible.

An interface can be implemented just by having the same structure that the interface requires, without an explicit implements clause.

Example

interface Person {
    firstName: string;
    lastName: string;
}
function greeter(person: Person) {
    return "Hello, " + person.firstName + " " + person.lastName;
}
  • Then create an object of this type and calling the typed function. <note tip>A user is a person because it has the same structure than the interface declaration.</note>
let user = { firstName: "Jane", lastName: "User" };
document.body.textContent = greeter(user);

Powered by ComboStrap