Catching Errors in the Browser

The TypeScript compiler doesn’t catch all errors, though. Sometimes you can only catch them in the browser. Let’s assume you’ve got an html webpage like this (index.html) that does nothing but run a compiled TypeScript (i.e., a Javascript) file:

Here, we pass the undefined variable to func1, which then passes that same variable to func2, which then tries to determine the length. But an undefined variable has no length, so an error is produced.

Here’s the output in Firebug:

Click on the little arrow to the left of the error message and you can see the exact path the code took to get to that error. This path is called the stack trace:

You can also click on the blue-highlighted text to go to that line in the code. Makes debugging much easier.