title: What is the sturdiest way to get the closure compiler's type safety together with AMDs (requirejs)?
body: <p>Although JavaScript and its many libraries (jQuery, <a href="http://requirejs.org/" rel="nofollow">RequireJS</a>) allow for the creation of many great websites I find its lack of type safety daunting when contemplating building a larger website. </p>
  
  <p>Google has a wonderful <a href="https://developers.google.com/closure/compiler/" rel="nofollow">closure compiler</a> which allows you to <a href="https://developers.google.com/closure/compiler/docs/js-for-compiler" rel="nofollow">annotate</a> your JavaScript with JSDoc and have it type check. Having experimented with its rich type system I expect this would greatly improve the maintainability of a longer lived JavaScript project.</p>
  
  <p>The only problem is it doesn't play very nicely with <a href="https://github.com/amdjs/amdjs-api/wiki/AMD" rel="nofollow">AMD</a> libraries like RequireJS. There is an experimental <a href="http://www.nonblocking.io/2011/12/experimental-support-for-common-js-and.html" rel="nofollow">--transform_amd_modules</a> flag that concatenates your JavaScript files and handles scoping by eliminating it. However this seems to be a bit of an anti-pattern, removing most of the benefits of RequireJS (but keeping the modular file structure). There's also the question of how much future support that will get</p>
  
  <p>With the end goal being type-safety not at the expensive of RequireJS's benefits what would be my best bets?</p>
  
  <p>PS: Although I've used RequireJS as the AMD library of choice I would not be against a solution that worked with a different AMD library.</p>