Converted to Typescript because Closure Compiler Advanced gives good warnings but makes the code too ugly and requires too much baby-sitting to be worth it.