Description
See: https://typescript.codeplex.com/workitem/1542 by danieljsinclair
I would like to see TypeScript become a fully fledged optimizing compiler producing minified, but optimized JavaScript code similar to what the Google Closure compiler does.
In the same way we don't write ASM anymore, and we don't care if it's readable, we just want the smallest, fastest, most efficient JS code without optimizing coding practices at editing time. The compiler should take care of that.
I'm like with the near 1:1 JS output in developer mode, but as we have .map files now, and we minify for production anyway I don't think it's that important. I want to stop worrying about writing small functions and using var instead of const (where the compiler could introduce a literal in the output). I want it to optimise my const string 'tables' and concatenation. I want it to remove unnecessary/unused code, etc.
I'd like to see all this from the TypeScript compiler, without stringing together all the other technologies in my build.
I think the main issue is that true JavaScript doesn't have enough type information even by way of inference for a post-build step to achieve suitable optimization. I know that Java and .Net optimize at run time but C++ doesn't. C and C++ compilers like many others that don't produce type information need to optimize and compile time because that's where it's best.
I think TypeScript in this case falls into the C++ category because most of the type information is lost when it's turned into JavaScript and therefore true optimization can only be done well by the TS compiler.
Furthermore, a TypeScript project can be compiled as a unit rather than as an individual set of JS files. As such even things like removal of unused code is possible. Others have commented on the discussion thread that this is difficult for shared libraries which simply isn't true since the TypeScript project can consider and compile a series of TS files and produce a single output containing just the code it needs, whether one or multiple outputs.
The C++ compiler can optimize the output binary if it's working with the source files directly, but you wouldn't expect the same level of optimization of you only called into DLLs. Similarly, if you only consider the post-typed JavaScript for optimization you can't achieve optimal results.