Re:Why does TypeScript have be the answer to anything?
by disordinary on Wednesday October 03, 2012 @09:28PM
(#4610505)
The benefit of typing javascript is for the developer and not the compiler, therefore telling closure compiler that a variable is a type is to decrease the chance of mistakes. Closure compiler also is buggy and isn't as smart as we would like to think it is, sometimes you have to prod it into the right direction. It was a simplified example, something better would be:
/** @type {myType} */ var thing = function_that_returns_a_myType( );
The point is using comments for typing a language is messy and takes up far more space than required.
Also, I think that the first example is more likely to be written as follows (in the case where type data cannot be inferred):
Whatever "..." may be. It's common to document the meaning of variables where explicit typing like this is important, just like in well-documented Java and PHP code.