I am currently working with a function called search
, which at the moment is set up to return a type of Promise<MyObject[]>
:
export function search(args: SearchInput) {
return SomeInterface.performSearch(args)
.then(xmlRequest => AnotherInterface.post(xmlRequest))
.then(xmlResponse => SomeInterface.performSearchResponse(xmlResponse)) // performSearchResponse returns Promise<MyObject[]>
.then(searchResponse => searchResponse.forEach(convertIDs)); // returns Promise<void>
}
function convertIDs(obj: MyObject) {
if (obj.id === 'foo') {
obj.id = 'bar';
}
return obj;
}
I am facing an issue where I want to add a new line at the end that applies the convertIDs
function to the results of the original function. However, this adjustment causes the function to no longer return Promise<MyObject[]>
but instead Promise<void>
. Unfortunately, this change breaks other parts of the code that depend on the function returning Promise<MyObject[]>
.
Is there a solution or workaround that would allow me to apply the convertIDs
function to the results while still preserving the original return type?