tsconfig for beginners
Read the most common compiler flags and understand what each one actually changes.
- Turn on strict to enable a broad set of safety checks.
- Set target to the JavaScript version your runtime supports.
- Set module to how your bundler imports and exports code.
- Turn on noUncheckedIndexedAccess to catch missing lookups.
In plain English
The tsconfig file tells the TypeScript compiler how to behave. The strict flag turns on a bundle of checks that catch more mistakes, including accidental null and any. The target flag decides which JavaScript version the compiler emits, so newer targets keep newer syntax and older targets rewrite it. The module flag decides how files import and export each other. The noUncheckedIndexedAccess flag makes every array or record lookup possibly undefined, so you must handle a missing value before using it.
Step by step
- 1Open or create a tsconfig.json at the root of your project.
- 2Set strict to true and fix the errors it reports.
- 3Set target to the JavaScript version your environment supports.
- 4Set module to match your bundler, often ESNext.
- 5Turn on noUncheckedIndexedAccess and handle undefined lookups.
{
"compilerOptions": {
"strict": true,
"target": "ES2022",
"module": "ESNext",
"noUncheckedIndexedAccess": true,
"noEmit": true,
"skipLibCheck": true
},
"include": ["src"]
}Common mistakes
- Turning off strict to clear errors hides real bugs instead of fixing them.
- Setting target to a version newer than your runtime means your users get syntax their browser cannot run.
- Forgetting noUncheckedIndexedAccess lets a missing array item crash at runtime instead of at compile time.
- Changing module without updating your imports can break how files load each other.
Make the config strict
Add strict and noUncheckedIndexedAccess to a tsconfig. Explain in your own words why reading items[0] can now fail.
{
"compilerOptions": {}
}What does noUncheckedIndexedAccess change?
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Lock in what you just learned.
Mark this lesson complete to save your place and move one step closer to the certificate.