Challenge: Strict Compiler Options

Test your understanding of strict compiler options in TypeScript by applying your knowledge to real problems.

We'll cover the following

In this lesson, we will be addressing problems that require modifications to either the tsconfig.json or the index.ts file.

Throughout the challenge, you will come across code snippets that don’t work as intended. These errors might arise due to the absence of a key option in the configuration file, preventing the code from running correctly. Alternatively, some index.ts files may require modification due to a configuration option enabled in the tsconfig.json file.

As you work through the challenge, it’s important to determine which file requires tweaking to fix the compilation errors you encounter.

Assignment error

We have defined a variable named a that is of type number. We then define a variable named b and assign the value of a to it. This code will generate an error.

This error tells us that we are attempting to use the value of the variable a before it has been assigned a value. Remember that because it has not yet been assigned a value, it could still be undefined. What can we do to fix this error?

We can remove the error by making a change in the tsconfig.json file but also the index.ts file. Which file should we modify, and what changes do we need to make?

Let’s see if you can figure it out.

Get hands-on with 1200+ tech skills courses.