How to merge two interfaces with TypeScript?

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.