Closure Compiler: Checking Types

Last week, Google open sourced the Closure Compiler. Jared and I were working on this compiler during our time at on the Gmail team, and you can imagine how happy we were to see this fantastic tool out.

My main contribution to the project was the design and implementation of the type system. To use it, just apply this tiny patch.

$ cat test.js
/**
 * @param {string?} input
 */
function a1(input) { a2(input); }

/**
 * @param {string} input
 */
function a2(input) {}
$ java -jar compiler.jar --check_types --js test.js
test.js:5: WARNING - actual parameter 1 of a2 does not match formal parameter
found   : (null|string)
required: string
  a2(input);
     ^

0 error(s), 1 warning(s), 100.0% typed
function a1(a){a2(a)}function a2(a){};

Next post: description of the type system and a real-life example.