6 Testing and debugging TypeScript
This chapter covers
- Debugging TypeScript code using Visual Studio Code and the Node.js debugger
- Using a linter to find problems in code the com piler won’t detect
- Writing and executing unit tests on TypeScript code
In this chapter, I continue the theme of TypeScript development tools started in chapter 5, which introduced the TypeScript compiler. I show you the different ways that TypeScript code can be debugged, demonstrate the use of TypeScript and the linter, and explain how to set up unit testing for TypeScript code.
6.1 Preparing for this chapter
For this chapter, I continue using the tools project created in chapter 5. No changes are required for this chapter.
Tip
You can download the example project for this chapter—and for all the other chapters in this book—from https://github.com/manningbooks/essential-typescript-5.
Open a new command prompt and use it to run the command shown in listing 6.1 in the tools folder to start the compiler in watch mode using the tsc-watch package installed in chapter 5.
Listing 6.1 Starting the compiler
npm start
The compiler will start, the TypeScript files in the project will be compiled, and the following output will be displayed:
7:04:50 AM - Starting compilation in watch mode... 7:04:52 AM - Found 0 errors. Watching for file changes. Message: Hello, TypeScript Total: 600