Improved TypeScript binding generation. TODO: fix where type conflicts with namespace.