Better errors and more tests for typeCheck