Typescript update

Huge update; probably still bugs and some hacks, but certainly better and more compliant than what's currently in the repository.