Within my array of objects containing CustomObjects, each object contains a field called stringArray populated with an array of strings.
I am attempting to merge all the string arrays together using the following code:
const testArray = arrayOfObjects.reduce( (a,b) => {
return a.stringArray.concat(b.stringArray);
});
The TypeScript compiler is flagging an error indicating that the return type should be string[]
, while I actually intend for it to be of type CustomObject
. Is there a way to inform TypeScript that I do not wish to return a CustomObject
, but rather have my new constant testArray defined as a string[]
?
I've attempted to define it explicitly as const testArray: string[] = ...
, but to no avail.