I have the following type definition:
enum MixedResultType {
Abstract = 'ABSTRACT',
Section = 'SECTION',
}
type MixedSearchResult =
| {
type: MixedResultType.Abstract;
data: Abstract[];
}
| {
type: MixedResultType.Section;
data: Section[];
};
Abstract
and Section
share no common properties.
If I define an object with MixedSearchResult
:
const result: MixedSearchResult = {
type: MixedResultType.Abstract,
data: abs as Abstract[],
};
I will get an error saying
Type 'Abstract[]' is not assignable to type 'Abstract[] | Section[]'
The end goal is to have a MixedSearchResult
array with different type of search results.