Developing a typescript library
I’ve been building node libraries for home automation purposes for a while now, see my repositories. I decided that it was time to try out the strong-type goodness you get when using Typescript.
Node-sonos (a library to control your sonos device, from you guessed it, node) was a good candidate. I’m one of the main contributors at this point. In the last two months I spend a lot of hours developing a comparable library in typescript. The result node-sonos-ts is now at version 1.1.1 so it’s a good moment to look back on the bumps in the road.
Setup project
Setting up the project correctly is important. Before you can run (or debug) your typescript code it has to be compiled to JavaScript by tsc
. You’ll need to do some setup stuff, someone make a great tutorial. You can also have a look at the package.json and the tsconfig.json files in my new repository. In node-sonos-ts the files live in the src folder, and the get compiled (and released) from the lib folder.
Debugging
Getting your library to compile automatically is one thing, but debugging is might be as important! In node-sonos-ts is a special VSCode launch.json file. What it does is compiling the library to javascript (with source maps). And that way you can debug the typescript files really easy. You can set breakpoints and they are hit. You can even inspect all the current values.