Categories
TypeScript Answers

How to merge two interfaces with TypeScript?

Spread the love

Sometimes, we want to merge two interfaces with TypeScript.

In this article, we’ll look at how to merge two interfaces with TypeScript.

How to merge two interfaces with TypeScript?

To merge two interfaces with TypeScript, we can use extends to extend multiple interfaces.

For instance, we write

interface IFooBar extends IFoo, IBar {}

to create the IFooBar that extends IFoo and IBar.

This means IFooBar has all the members from both interfaces inside.

Conclusion

To merge two interfaces with TypeScript, we can use extends to extend multiple interfaces.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *