1

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 FormerGenericComponents

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!

1
  • can you simplify your question with simple Interfaces, I have no clue what Type and FormerComponent is Commented Apr 7, 2020 at 20:47

1 Answer 1

5
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[]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.