Skip to content Skip to sidebar Skip to footer

Typescript How To Declare A Subclass Type?

Is it possible to have something like this? export abstract class FilterBoxElement { abstract getEntities: any; } export interface FilterBoxControlSuggestions extends FilterBox

Solution 1:

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
}

Solution 2:

If it can be one type or the other, use a union type (|):

export interface FilterBoxDataProps {
    controlElement: FilterBoxControlSuggestions | FilterBoxControlDropDown;
}

Post a Comment for "Typescript How To Declare A Subclass Type?"