Port lib/typescript.js to TypeScript 0.9.5

Issue #265
Closes #288
Closes #289