From the course: TypeScript for Node.js Developers

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Introduction to declaration merging

Introduction to declaration merging

From the course: TypeScript for Node.js Developers

Start my 1-month free trial

Introduction to declaration merging

- [Instructor] Declaration merging is literally what it sounds like. It's a syntax method to allow you to declare multiple properties with the same name. For example, declaring the same interface twice and inserting different properties. TypeScript would merge them together. So you can use it with interfaces, name spaces and classes. So let me demonstrate. So let's go ahead and go back to our index.ts and let's scroll all the way down to where we did the let my name so I'm going to add an interface called warriors, something that I've used in one of my courses. And then inside of that interface we'll define a weapon property and we expect string and then we'll define skills and we expect number for this one. So this is where declaration merging comes into play. So I wanted to add more stuff to the warriors interface but I don't want to add it here, so you could create multiple interfaces with the same name and merge all these different things. So let's create an interface again and…

Contents