Ensure generic type has certain property

Create an interface and add an extends restriction to the type parameter T:

export interface IHelicopterStructure {
    listOfEngines:string[];
}

export class Helicopter<T extends IHelicopterStructure> extends Structure implements IFlyable<T> {
    ...
}

What you are looking for is called constraining:

https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-constraints

Just specify the type or interface T must extends as shown in the manual.

export class Helicopter<T extends IVehicle> implements IFlyable<T> {}

Tags:

Typescript