If we consider having code structured like this:
function updateById(
collection: Record<string, any>[],
id: number,
patch: Record<string, any>
): any[] {
return collection.map(item => {
if (item.id === id) {
return {
...item,
...patch
};
}
return item;
});
}
function updateRefById(
collection: Ref<Record<string, any>[]>,
id: number,
patch: Record<string, any>
): void {
collection.value = updateById(collection.value, id, patch);
}
We have a generic function called updateById and a more specific one named updateRefById which acts as a wrapper. It's noticeable that there is some redundancy in type checking since both functions share almost the same arguments.
Is there a way to reduce this redundancy and make the code more concise?
The only potential solution that comes to mind is passing all the function arguments through a single options object. However, I'm unsure about whether or not this approach would be suitable for our needs.