Visit complete TypeScript roadmap

← Back to Topics List

Interfaces

Interfaces in TypeScript provide a way to define a contract for a type, which includes a set of properties, methods, and events. It’s used to enforce a structure for an object, class, or function argument. Interfaces are not transpiled to JavaScript and are only used by TypeScript at compile-time for type-checking purposes.

Here’s an example of defining and using an interface in TypeScript:

interface User {
  name: string;
  age: number;
}

const user: User = {
  name: 'John Doe',
  age: 30
};

In this example, the User interface defines the structure of the user object with two properties, name and age. The object is then typed as User using a type-assertion: User.

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