I have a function which takes an array of objects which do not have an id property and return all those objects with an id property added to them.
const pickIdAndDocs = (arr) => {
return arr.map(doc => ({
id: 1,
...doc
}))
}
Now, for example if i have this interface
interface iUser {
name: string;
}
and an array containing values of type iUser
let users: iUser[] = [ {name: "John"}, {name: "Joe"} ];
How do i specify the return type of the function pickIdAndDocs, such that it returns an array where each item is an extended type of the input type it takes with an added id property
function pickIdAndDocs<T>(items : T[] ) : extendedT[];
This function can take an array of any type (will always be objects/key-value pairs), an return all items with an appended id property.
Or am i approaching this the wrong way? Thanks :)