Table of Contents

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;
}
let user = { firstName: "Jane", lastName: "User" };
document.body.textContent = greeter(user);