Posts Tagged ‘TypeScript’

Upgrade Pains with 3rd Party Libraries in TypeScript

Most TypeScript developers know that one of the pain points of the ecosystem has traditionally been its integration with 3rd party libraries. As we begin 2018, the DefinitelyTyped project has finally matured to the point where grabbing a d.ts definition file for most libraries is only an npm install away (provided that you’re using TypeScript 2.0 or later). The problem has been solved well.

However, I recently tried to upgrade one of my Hapi.js projects from v16 to v17. Hapi v17 is a major rewrite of the entire framework, which includes a complete refactor to use async/await instead of callbacks. Upgrades like this generally have serious implications for the API (and therefore the typings) of the framework.

This is both good and bad.

The massive "win" is that by upgrading to the v17 typings TypeScript identifies all problem areas with my code. Much like when upgrading a DLL in a .NET project and your compilation breaks. I think this is a benefit that is often overlooked when most think about strong typing.

The downside is that the typings aren’t always available immediately, or even soon, after the official release of the new versions of libraries and frameworks. Upgrading libraries that haven’t made TypeScript support a priority will always incur delays. In this case, the typings for hapi v17 have been stuck in pull requests since December 11th, 2017, and were authored only shortly earlier by a very helpful contributor (for whom I have immense gratitude).

Because this PR hasn’t been merged yet, I’ve had to manually pull these typings and track the progress of the PR. While this is a good thing (we want high-quality typings), it’s a gap in the TypeScript world that has been frustrating for me.

This is not a complaint. The contributors putting together the typings for hapi have done a great job. If anything, this is a plea for framework and library developers to take a more active stance toward including TypeScript typings in-project or supporting the development of external typings in the DefinitelyTyped repository.

As a TypeScript developer it’s hard not to love a library for simply making rich and accurate typings available. Bring us typings and we will adopt!