Typescript - Interface (Implement)


Data Type - Interface (Abstract Type) in Typescript

An interface is a type that describes objects


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.


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. A user is a person because it has the same structure than the interface declaration.
let user = { firstName: "Jane", lastName: "User" };
document.body.textContent = greeter(user);

Discover More
Javascript - Typescript

TypeScript is a typed superset of JavaScript that compile to plain JavaScript. It adds static typing. JSdocReference See When...

Share this page:
Follow us:
Task Runner