I am working with a function parameter that accepts an array union, like this: (ClassA|ClassB)[]
.
How can I return either ClassA[]
or ClassB[]
from the function?
When attempting to return type (ClassA|ClassB)[]
, I encounter the following error:
Assigned expression type
(ClassA|ClassB)[]
is not compatible with typeClassA[]
.
classA: ClassA[];
classB: ClassB[];
this.classA = this.function(this.classA, classAObject);
this.classB = this.function(this.classB, classBObject);
function(array: (ClassA|ClassB)[], item: ClassA|ClassB): any {
// some code...
return array;
}