Wednesday, April 10, 2013

Migrating Javascript to Typescript Tip : Sealed classes

Sealed classes in Javascript are made using the revealing module pattern.
In this case when you migrate the typescript classes all your variables names must suddenly be prefixed with this keyword.
Problem is that this in callbacks is going to be the window object.

So you need to convert functions (being passed as an argument into another function ... i.e. a callback)  that look like:

Into arrow functions:

To make sure that this gets captured properly in the generated Javascript. A quick way to do this is to search for all instances of function since its really not required to use this keyword in typescript classes.