5

I'm preparing for the js13k game dev competition and have been searching for ways to minify TypeScript code. Base on this SO question from 4 years ago, the solution seems to be compiling TypeScript code to JS and use the regular js tools but in doing so you lose all the valuable type information.

Is there any way to make use of TypeScript's types to better minify and optimize the code's output?

7
  • TypeScript's output is JavaScript. And of course the typing information is lost, because only TypeScript's compiler cares about the types. To answer the question; I'm sure there is a way, but explaining it is likely to take far more words than are allowed in an answer on Stack Overflow. Commented Jul 17, 2017 at 16:52
  • I don't think that there's an existing tool for that. There's a suggestion to make it part of the language. I'm pretty sure that you're best (and only) option is to use js minifyers, and there are some good ones out there, for example take a look at the google closure compiler Commented Jul 17, 2017 at 16:58
  • I have looked into the Closure compiler before but that requires you to write JSDoc comments containing type above everything which seems pretty inefficient and messy when TypeScript syntax has the types. Commented Jul 17, 2017 at 17:35
  • Well, try TypeDoc to produce the comments from the types, maybe then you'll be just able to use closure? I've never used any of those so I can't say for sure, but it might be worth looking into Commented Jul 17, 2017 at 19:52
  • Why don't you just compile your Typescript to Javascript and then minify it? Commented Jul 17, 2017 at 22:33

1 Answer 1

2

I know this question is two years old, but I ran across this question looking for something similar and this is what I've found so far (note that the latter two, at time of writing, both are works in progress):

  1. typescript-plus: a TypeScript compiler that includes some additional compiler features, including some optimizations.
  2. ts-optimizer: a proof-of-concept TypeScript optimizer.
  3. Tsickle + Closure Compiler: Tsickle is a code transpiler from Google that converts TypeScript code into JavaScript code that is acceptable to Google's Closure Compiler. Closure compiler then analyzes your code and strips unused portions then optimizes and minifies the rest. The Closure Compiler is capable of leveraging type information via its own variation of JSDoc annotations.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.