Visit complete TypeScript roadmap

← Back to Topics List

Interface Declaration

An interface in TypeScript is a blueprint for creating objects with specific structure. An interface defines a set of properties, methods, and events that a class or object must implement. The interface is a contract between objects and classes and can be used to enforce a specific structure for objects in your code.

Here is an example of an interface declaration in TypeScript:

interface Person {
  firstName: string;
  lastName: string;
  age?: number;

  getFullName(): string;
}

In this example, the Person interface defines four properties: firstName, lastName, age, and a method getFullName(). The age property is optional, indicated by the ? symbol. Any class or object that implements the Person interface must have these properties and method.

Learn more from the following links:

Roadmaps Guides Videos About YouTube

roadmap.sh by Kamran Ahmed

Community created roadmaps, articles, resources and journeys to help you choose your path and grow in your career.

© roadmap.sh · FAQs · Terms · Privacy