Reputation: 453
I have an interface that contains a property which is an array containing 2 different possible object types:
<Type>FormerComponent and FormerGenericComponent
Here are my interfaces
interface FormerConfigColumn {
container: ViewContainerRef
components?: Type<FormerComponent>[]|FormerGenericComponent[];
}
interface FormerGenericComponent {
component: Type<FormerComponent>;
}
The above doesn't work the way I would like it to. I think the above defines an array containing only Type<FormerComponent>
s or only FormerGenericComponent
s
I want FormerConfigColumn.components to contain an array of objects, and said objects can either be Type<FormerComponent>
or FormerGenericComponent
.
How can I do this?
Thanks!
Upvotes: 1
Views: 938
Reputation: 821
interface FormerConfigColumn {
container: ViewContainerRef
components?: (FormerComponent | FormerGenericComponent)[];
}
This will define components
as an optional property of FormerConfigColumn
that holds an array which can be filled with FormerComponent
or FormerGenericComponent
.
If you want components
to hold an array of FormerComponent
or FormerGenericComponent
, but not both at the same time, then use:
components?: (FormerComponent[] | FormerGenericComponent[]);
Upvotes: 5