Revise TypeScript support with tweaks from olov