The tsconfig.json File
The tsconfig.json File
TypeScript features are extremely useful: for one, it allows us to add types to regularJavaScriptcode. It also checks for syntax errors even before run time. It even provides tooltips that show you why some code might throw an error. There are so many great features that come by default. Even with all these great features, TypeScript recognizes the need for flexibility.
Sometimes, you don’t want all thedefault rulesthat TypeScript is trying to enforce — and that’s fine. That’s one reason why providing atsconfig.jsonfile is useful. Additionally, you get perks like telling the TypeScript compiler what files to run on and more! So, let’s explore what this file looks like and how it helps.
Sample tsconfig.json and Breakdown
Thetsconfig.jsonfile is always placed in the root of your project and you can customize what rules you want the TypeScript compiler to enforce. Here’s thetsconfig.jsonfile we provide in every single exercise and project in our Learn TypeScript course:
{ "compilerOptions": { "target": "es2017", "module": "commonjs", "strictNullChecks": true }, "include": ["**/*.ts"]}
Copy to clipboard
{ "compilerOptions": { "target": "es2017", "module": "commonjs", "strictNullChecks": true }, "include": ["**/*.ts"]}
In theJSON, there are several properties:
- "compilerOptions", which is a nested object that contains the rules for the TypeScript compiler to enforce."target", the value"es2017"means the project will be using the 2017 version of EcmaScript standards for JavaScript."module", this project will be using"commonjs"syntaxto import and export modules."strictNullChecks", variables can only havenullorundefinedvalues if they are explicitly assigned those values.
- "include"that determines what files the compiler applies the rules to. In this case["**/*.ts"]means the compiler should check every single file that has a.tsextension.
We chose these rules because we wanted to give you an idea of what rules to enforce and still allow your creativity to shine. For your own projects, you can set these rules to your own preferences! Thetsconfig.jsonfile is great for both individual work and team projects because it allows everyone to be on the same page about how to write their code.
Usage
Another neat addition is that by including atsconfig.jsonfile, you can now use the commandtscwithout any arguments in your terminal! The compiler will automatically recognize from yourtsconfig.jsonfile, what specific files to run on. You can still provide specific files liketsc fileName.tsif that’s the only file you want the compiler to check.
Wrap up
Check out TypeScript’scompiler option documentationfor even more information.
Happy Coding! And remember, when in doubt,typeit out!
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Complete Payment to Unlock Full Guide & Source Code
You are viewing the 30% preview. Join TopCourseAI Pro to unlock the remaining 70% of this article, unblur all code snippets, and gain full access to all 412 technical projects and guides.
Ready to access the complete step-by-step tutorial?
Gain full unhindered access to all 412 technical projects and guides, unblur all source code snippets, and download runnable scripts.
Related Project Guides
View all 412 →Accessibility on the Platform
Codecademy is committed to providing a high-quality learning experience for all learners. That includes accommodating different usage forms such as auditory, motor, or visual restrictions, limited hardware, or other acce...
Web developmentAffordances, Signifiers, and Clickability
For users on the web, the mouse click is perhaps the most fundamental human-computer interaction. The webbecamethe web partially through the power ofhypertext, or text in one document that links to other documents or res...
Web developmentAuthentication and OAuth
Authenticationis the process used by applications to determine and confirm identities of users. It ensures that the correct content is shown to users. More importantly, it ensures that incorrect content is secured and u...
Ready to start building your next project?
Enjoyed this guide? Continue exploring our library of 412+ step-by-step guides, starter files, and practical projects across Web Development, Mobile Apps, AI, and Design.