Search code examples
javascripttypinggoogle-closure-compilerjsdoc

Google Closure Compiler 100% typed


How can I get my application to be 100% typed in regard to google closure compiler?

I already tagged everything with jsdoc comments. Is it even possible to get 100? I'm at 64,6%


Solution

  • It IS possible to achieve 100%. My own projects are 100% typed. The closure compiler can output warnings about expressions with unknown types. Unfortunately there is no command line option to enable this feature. You have to modify the source code to enable it:

    1. Download the current sources:

      git clone https://code.google.com/p/closure-compiler/

    2. Edit src/com/google/javascript/jscomp/CompilerOptions.java and change the line reportUnknownTypes = CheckLevel.OFF to reportUnknownTypes = CheckLevel.WARNING

    3. Compile the closure-compiler by simply calling ant in the root directory. The modified compiler.jar is now in the build directory.

    When you use this modified compiler on your scripts then it spits out lots of warnings about all the expressions for which the compiler couldn't determine the type. When you fix all these warnings in your code then it is 100% typed.