Skip to content

Move to TypeScript

von Schappler edited this page Oct 18, 2024 · 2 revisions

Working with TypeScript

The first common approach to move the code from Javascript to TypeScript would simply rename the file extension from .js to .ts.

Doing this will mark the file with lots of red underline marks, which are going to show possible sources of error on your code. Hovering those, it's possible to see what TypeScript detects as a possible error source and this gives us a hint on how we could fix those.

Some of the possible errors sources displayed on your text editor / ide can be easyly fixed just by changing the way in which some of the variables are declared on the code - while others really will depend on other TypeScript fundamentals.

In the code provided, those errors which can be easly fidex, are marked with Cannot assing to 'xxxx' because it's a constant. Changing those declarations from const to let would be a possible fix.

At first glance, seeing all those errors showing up on your screen can be really intimidating - specially when we think about all the additional code required to fix those errors - , but once you get hold of this, things will become clear, confortable and your coding worl will have lots of improvements. This happens not because TypeScript is creating new bugs on the code, but only showing where those bugs already existed.

Clone this wiki locally