To use the extend function from the Underscore library in TypeScript, you need to first install Underscore:
index.ts23 chars2 lines
Then, you can import the library and use the extend function as follows:
index.ts220 chars10 linesThe extend function merges the properties of obj2 into obj1, and returns obj1 with the merged properties. The result variable in the above example will contain { name: 'John', age: 25, gender: 'male' }.
Note that the extend function modifies the original object (obj1 in the above example), so use it carefully. If you want to create a new object without modifying the original ones, you can pass an empty object as the first parameter:
index.ts41 chars2 lines
This will create a new object with the properties from obj1 and obj2, and leave the original objects unchanged.
gistlibby LogSnag