DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Subtitles: The Good, the Bad, and the Resource-Heavy
  • Integrating Jenkins With Playwright TypeScript: A Complete Guide
  • Efficiently Migrating From Jest to Vitest in a Next.js Project

Trending

  • Enforcing Architecture With ArchUnit in Java
  • Using Python Libraries in Java
  • The Smart Way to Talk to Your Database: Why Hybrid API + NL2SQL Wins
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  1. DZone
  2. Coding
  3. JavaScript
  4. What Is the tsconfig.json Configuration File?

What Is the tsconfig.json Configuration File?

We continue our series on TypeScript development by looking a particular configuration file that is quite handy in TypeScript-based web applications.

By 
Kunal Chowdhury user avatar
Kunal Chowdhury
·
Updated Jul. 03, 18 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
55.2K Views

Join the DZone community and get the full member experience.

Join For Free

The tsconfig.json file allows you to specify the root level files and the compiler options that requires to compile a TypeScript project. The presence of this file in a directory specifies that the said directory is the TypeScript project root.

In this chapter of the TypeScript Tutorial series, we will learn about tsconfig.json, it's various properties, and how to extend it.

In the previous chapters of this TypeScript Tutorial series, we learned how to install Node.js and TypeScript, followed by building your first Hello World application in TypeScript using Visual Studio Code. Today in this article, let's go one step ahead to learn about tsconfig.json file.

The "compilerOptions" Property

The "compilerOptions" property allows you to specify additional options to the TypeScript compiler. Here's a list of few optional settings part of the compilerOptions property that you may need most of the time: listFiles, module, outDir, outFile, rootDir, sourceRoot, allowUnreachableCode, allowJs, noImplicitUseStrict, strictNullChecks and more.

Here's a sample JSON file describing how you can define a tsconfig.json file containing different parameters of the compilerOptions property:

{
    "compilerOptions": {
        "module": "system",
        "noImplicitAny": true,
        "removeComments": true,
        "allowUnreachableCode": false,
        "strictNullChecks": true,
        "outFile": "../JS/TypeScript/HelloWorld.js",
        "sourceMap": true
    }
}

The "compileOnSave" Property

The "compileOnSave" property can be used to direct the IDE to automatically compile the included TypeScript files and generate the output. Here's how you can define the compileOnSave property inside a tsconfig.json file, along with the other properties:

{
   "compileOnSave": true,
   "compilerOptions": {
        "module": "system",
        "noImplicitAny": true,
        "removeComments": true,
        "allowUnreachableCode": false,
        "strictNullChecks": true,
        "outFile": "../JS/TypeScript/HelloWorld.js",
        "sourceMap": true
   }
}

The "files", "include" and "exclude" Properties

  • The "files" property allows you to specify a list of TypeScript files that will be included by the compiler. The URL of the files can be relative or absolute.
  • The "include" property allows you to include a list of TypeScript files using the glob wildcards pattern.
  • The "exclude" property allows you to exclude a list of TypeScript files using the glob wildcards pattern.
  • When you don't specify both the files and include properties, the compiler includes all TypeScript files (*.ts, *.d.ts, *.tsx) by default.
  • When both the files and include properties are specified, the compiler includes the union of the specified files.
  • When you want to filter out some files included using the include property, you can specify theexclude property.
  • If you specify any files using the files property, the uses of the exclude property will not have any impact on those listed files. In short, the files included using the files property will always be included regardless of the files listed under the exclude property.

Here's the code snippet describing how you can define the files, include, and exclude properties inside a tsconfig.json file, along with the other properties:

{
   "compileOnSave": true,
   "compilerOptions": {
        "module": "system",
        "noImplicitAny": true,
        "removeComments": true,
        "allowUnreachableCode": false,
        "strictNullChecks": true,
        "outFile": "../JS/TypeScript/HelloWorld.js",
        "sourceMap": true
   },
    "files": [
        "program.ts",
        "sys.ts"
    ],
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "src/**/*.spec.ts"
    ]
}

Extending the "tsconfig.json" File

You can also extend a TypeScript configuration file from a different base configuration. You can do so by using the extends property. It accepts a string value containing a path to another configuration file to inherit from. The configuration from the base file is loaded first, then overridden by those in the inheriting config file. If there is a circular reference, the TypeScript compiler will return an error.

// tsconfig-base.json
{
    "compilerOptions": {
        "module": "system",
        "noImplicitAny": true,
        "removeComments": true,
        "allowUnreachableCode": false,
        "strictNullChecks": true
    }
}

// tsconfig.json
{
    "extends": "./tsconfig-base",
    "compilerOptions": {
        "outFile": "../JS/TypeScript/HelloWorld.js",
        "sourceMap": true
    }
}
Property (programming) TypeScript

Published at DZone with permission of Kunal Chowdhury, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Subtitles: The Good, the Bad, and the Resource-Heavy
  • Integrating Jenkins With Playwright TypeScript: A Complete Guide
  • Efficiently Migrating From Jest to Vitest in a Next.js Project

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!