I'm refactoring some TypeScript and have come across something that has me stuck.
In the code below, how does the "as" keyword convert a Map<number, Trip> into a "Trip" object? If it isn't then what is it doing?
public mergeBookings(bookingData: Immutable.Map<number, Booking>) {
// merge bookings
const bookings: Immutable.Map<number, Booking> = this.mergeBookingData(bookingData);
// sort bookings
const sortedBookings: Immutable.Map<number, Booking> = SortingService.sortBookings(bookings);
// add bookings to trip
const trip: Map<number, Trip> = this.setBookingData(sortedBookings);
return trip as Trip;
}
An explanation on the keyword, how it works for maps and other objects and some documentation on it would be good but any information would help in maintaining this code base.
In particular I wanted to update the function definition to include the return type but need to be confident that it is indeed a "Trip" object. Example desired function definition below:
public mergeBookings(bookingData: Immutable.Map<number, Booking>): Trip {...}
I've looked around StackOverflow answers to this for TypeScript and a long google session for documentation hasn't turned up any help. As per tags this code is using:
TypeScript
Angular
Immutable.js