I have the following class and a subclass
export class FlightInfoModel {
carrierName?: string;
originCode?: string;
destCode?: string;
flightDetails: FlightSegmentEntity[];
constructor() {
this.carrierName = "";
this.originCode = "";
this.destCode = "";
this.flightDetails = new Array<FlightSegmentEntity>();
}
}
export class FlightSegmentEntity {
CarrierCode: string;
FlightNo: string;
Aircraft: string;
OriginCode: string;
DestinationCode: string;
DepartureDate: string;
ArrivalDate: string;
FlightDuration: number;
StopOverDuration: string;
constructor() {
this.CarrierCode = "";
this.FlightNo = "";
this.Aircraft = "";
this.OriginCode = "";
this.DestinationCode = "";
this.DepartureDate = "";
this.ArrivalDate = "";
this.FlightDuration = -1;
this.StopOverDuration = "";
}
I am using Typescript and UnderscoreJS to write the following function. flight is the FlightInfoModel object and flightDetails is the FlightSegmentEntity[]
_.reduce(flight.flightDetails,
function(memo, seg){ return memo + seg.FlightDuration + seg.StopOverDuration; },
0)
The underscore function accepts an array collection but I keep getting the following error
error TS2345: Argument of type 'FlightSegmentEntity[]' is not assignable to parameter of type 'Dictionary<{}>'. Index signature is missing in type 'FlightSegmentEntity[]'.
I have read a lot about the contextual typing that Typescript requires and tried doing that but to no avail. BTW I am using Typescript 2.3.4