Typed Amadeus (Typescript, Amadeus Client)

The main reason that my favorite language is Typescript is because of its typing - autocomplete on my IDE, robustness in knowing what I'm getting and what I need to provide. However, when libraries aren't typed, it's a little bit of a headache including it in a TS project. This happened to me when working with the Amadeus client over my flight tracking project - so I decided to write types for it. Check it out here.

Amadeus Client

When I was building my Flight Tracker, I realized that the Amadeus Client for Javascript was not typed in the slightest, meaning I had to rely a LOT on documentation and hacky integrations with my code. In fact from what I saw on forums, developers preferred using REST to the client because of the poor Typescript integration. And most importantly, there was no autocomplete.

// @ts-ignore
import Amadeus from "amadeus";

const amadeus = new Amadeus();
amadeus.icandowhatever.anditwontraiseanerror()

Writing Your Own Types

Typescript, as the name suggests, relies on typing, and they natively allow you to type other libraries if they don't have any, like Amadeus. You always start out with a .d.ts file with some exports (here, the syntax is a little weird for CJS compatibility):

declare module "amadeus" {
   class Amadeus {
    
   }

   export = Amadeus;
}

Then, it's just the process of going through the ~30 endpoints Amadeus offers and typing query parameters, request bodies, and responses. It was particularly tough since the database models often didn't correlate between endpoints (for instance, an Address model would have different members for the Hotel or Flight urls), so it was difficult to re-use components. However, after much trial and error, I ended up with a collection of types I felt was pretty on point for most of the endpoints, and definitely better than going in blind with the bane of any Typescript developer: any.

Next Steps

Typescript maintains an amazing repository called DefinitelyTyped, which allows members of the community to contribute for untyped projects. My own Amadeus types will likely require cleanup to submit to its lengthy approval process, but I have no doubt it'd be a huge help to developers out there.