Is it possible to have something like this?
export abstract class FilterBoxElement {
abstract getEntities: any;
}
export interface FilterBoxControlSuggestions extends FilterBoxElement {
getEntities: // some implementation with different parameters
}
export interface FilterBoxControlDropDown extends FilterBoxElement {
getEntities: // some implementation with different parameters
}
export interface FilterBoxDataProps {
controlElement: FilterBoxElement // FilterBoxControlSuggestions or FilterBoxControlDropDown
}
I want that controlElement
has to be a FilterBoxControlSuggestions
or a FilterBoxControlDropDown
. But right now I can put everything in it. Is there a way to achieve this?
You could do it with a union type:
export interface FilterBoxDataProps {
controlElement: FilterBoxControlSuggestions | FilterBoxControlDropDown
}
Or with generics if you want all subclasses of FilterBoxElement:
export interface FilterBoxDataProps<T extends FilterBoxElement> {
controlElement: T
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With