Better error reporting for invalid type specifications

Closes #818