Revisiting moving to TypeScript


(Sean) #1

Around a year ago, @eviltrout has previously expressed reasonably cautious interest in moving to TypeScript. Having recently started using it in my own development projects, I’ve been slowly figuring out how to integrate TypeScript build tools (tslint, tsc and ts-loader) into established projects.

My questions are as follows:

  • Is there still interest in using TypeScript?
  • What is the JavaScript build process of this project? I know you’re using babel to convert from es6 to es5 and I looked at the docs, but where it’s called seemed a bit hidden? I’m assuming you have a build script of some sort?

(Joshua Rosenfeld) #2

Some quick notes:

That was actually over two years ago.

The ES5 :arrow_right: ES6 conversion finished 9 months ago which may explain why you’re not seeing references to it in the code.


(Robin Ward) #3

Since then (two years really flies by!) I have had the opportunity to play with TypeScript a bit more and I can say that I am quite a fan.

I would not suggest it for everything in Discourse, but there are parts of the codebase where stronger typing would certainly help from a development perspective. I consider TypeScript something like a super linter, where you can avoid null exceptions and accessing members that aren’t there.

The big problem right now is the pipeline doesn’t support it. Our current JS build process is still based on sprockets in Rails, with a bunch of custom code to use Babel for ES6 features.

We’ve had some internal discussions about reviewing other build pipelines such as rollup, ember cli or webpack to see if those tools can be used instead of sprockets. There are several advantages to this:

  • Our sprockets hacks are holding us back from upgrading Rails right now
  • Not upgrading Rails is holding us back from the newer version of Ruby which has better memory usage/performance
  • Sprockets is really slow and uses a lot of memory. We’d like to be able to upgrade Discourse without hitting swap on low memory servers.
  • We’d like to improve development speed
  • We’d like for front end designers to work on Discourse locally without the entire ruby app

I suspect that based on internal discussions that we will have an opportunity to look into a new build pipeline this year (maybe even this quarter). Once that is in place we will be in a much better position to add something like TypeScript.


(Sean) #4

Thanks for the informative post.

I consider TypeScript something like a super linter, where you can avoid null exceptions and accessing members that aren’t there.

That’s how I’ve used it as well. It’s personally saved me a ton of time.

We’ve had some internal discussions about reviewing other build pipelines such as rollup, ember cli or webpack to see if those tools can be used instead of sprockets.

I only have experience with Webpack2, so I can’t really comment on the difference between Rollup and Webpack2. Please ping me when the internal discussions have concluded!