I need to extend a generic list of Array which has been extended from my class. How to do it properly?
export interface DeliveryMethod {
readonly id: string;
readonly company: string;
readonly cost: number;
readonly threshold: number;
readonly intervals: Array<Interval>;
readonly paymentMethods: Array<PaymentMethod>;
}
export interface Delivery {
selected: SelectedDelivery;
available: { [key : string] : Array<T extends DeliveryMethod>};
}
Cannot find name 'T'.ts(2304)
available: { [key : string] : Array<T extends DeliveryMethod>};
For example i need something like that:
const Delivery = {
selected :{/*data inside*/},
available:{
pickup: [<Pickup>{},<Pickup>{}],
courier: [<Courier>{},<Courier>{}]
}
}
export interface Delivery<T>- you need to declare your generic parameter.export interface Delivery<T extends DeliveryMethod>- you should declare the generic parameter with its constraints as part of the interface declaration (or method/function declaration for a generic version of that when you have it). Once you've declared the parameter, you can then just use it within your interface as just the generic parameter name:available: { [key : string] : Array<T>};.Array<DeliveryMethod>? I'm guessing anything that extends it would also work?