Visit complete TypeScript roadmap
TypeScript Topic

Interface Declaration

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:

More Topics

Explore related content

View All Topics
Loved by 100K+ Developers

Start Your Learning
Journey Today

Join thousands of developers who are leveling up their skills with structured roadmaps and expert guidance

No credit card required
Always free
Track your progress