There was a mistake in the shared code, since I was using Typescript typings inside a JS file.
I've updated the code in the article to fix that, but you can see the gist directly on github: https://gist.github.com/3nvi/91db00834bfd52bc4d8f0b29bf836c6b
P.S. At the end of the article, I'm linking to an OSS library I've created, which does everything I explain in this article and is probably a bit more stable than those code snippets. See if it suits your needs :)