When chaining functionality in typescript
with anonymous types for example like this:
let array = [{ seed: 2 }, { seed: 3 }];
array
.map(i => ({ seed: i.seed, square: i.seed * i.seed }))
.forEach(i => console.log(`square for ${i.seed} is ${i.square}`));
I need to define new anonymous type for map function. If I would have multiple steps all producing new properties, I'd end up writing lots of definition code to get all properties carried over.
I could use $.extend
(or Object.assign
), but that way I'll lose intellisense and strong typing.
array
.map(i => $.extend(i, { square: i.seed * i.seed }))
.forEach(i => console.log(`square for ${i.seed} is ${i.square}`));
How can I extend anonymous object without defining all properties again while keeping strong typing?