HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / TypeScript / tsconfig.json – TypeScript Compiler Configuration

tsconfig.json – TypeScript Compiler Configuration

TypeScript compiler uses tsconfig.json to get configuration options for generating JavaScript code from TypeScript sourcecode. When you uses '$ tsc' command to compile TypeScript code, compiler searches for configurations loaded in tsconfig.json.

Create tsconfig.json

Before you start using TypeScript, make sure you have installed it. To use conveniently, install it as global dependency so that you can use tsc command from console window.

Then use 'tsc --init' command to create tsconfig.json file in your project’s root folder.

$ npm install typescript -g 	//Install typescript

$ cd project_root		//Go to project's root folder

$ tsc --init			//Create tsconfig.json in project's root folder

A default tsconfig.json will be created.

{ 
   "compilerOptions":{ 
      "target":"es6",
      "moduleResolution":"node",
      "module":"commonjs",
      "declaration":false,
      "noLib":false,
      "emitDecoratorMetadata":true,
      "experimentalDecorators":true,
      "sourceMap":true,
      "pretty":true,
      "allowUnreachableCode":true,
      "allowUnusedLabels":true,
      "noImplicitAny":true,
      "noImplicitReturns":false,
      "noImplicitUseStrict":false,
      "outDir":"dist/",
      "baseUrl":"src/",
      "listFiles":false,
      "noEmitHelpers":true
   },
   "include":[ 
      "src/**/*"
   ],
   "exclude":[ 
      "node_modules"
   ],
   "compileOnSave":false
}

Complier Options

Let’s go through some important compiler options, you must know.

OptionDescription
allowJsAllow JavaScript files to be compiled. Default value is false.
alwaysStrictParse in strict mode and emit “use strict” for each source file. Default value is false.
moduleThe output module type e.g. “CommonJS”, “AMD“, “System“, “ES6“, “ES2015” or “ESNext“.
Default value is CommonJS if target attribute is ES3 or ES5; else default is ES6.
targetSpecify ECMAScript target version. Default value is ES3.
moduleResolutionDetermine how modules get resolved. For module type ES6, AMD or System – default value is classic; else Node.
sourceMapIndicates to generate sourcemap or not. Sourcemaps helps in debugging.
outDirThe location in which the transpiled files should be kept.
baseUrl or pathsInstructing TypeScript where it can find the type files.
watchUsed for livereload. It means that whenever any of the source file is changed, then the compiling process is re-triggered to generate the transpiled files again.
experimentalDecoratorsThis option enables using decorators in TypeScript projects. ES has not yet introduced decorators, so they are disabled by default.

Follow official page for complete list of complier options.

Include and exclude options

These options takes an array of global patterns that need to be included in the compilation path, to add or remove files from compilation process.

"include":[ 
  "src/**/*",
  "src/app/shared/**/*",
  "typings/*.d.ts"
],
"exclude":[ 
  	"node_modules",
	 "jspm_packages",
	 "application", 
	 "system",
	 "dist"
]

Drop me your questions in comments section.

Happy Learning !!

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.
TwitterFacebookLinkedInRedditPocket

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Feedback, Discussion and Comments

  1. RB

    September 2, 2019

    Typo on the typescript install:

    $ npm uninstall typescript -g   //Install typescript
    

    should be

    $ npm install typescript -g   //Install typescript
    
    • Mithin k

      March 11, 2020

      $ npm uninstall typescript -g //Install typescript
      its a unstall

Comments are closed on this article!

Search Tutorials

TypeScript Tutorial

  • TypeScript – Introduction
  • TypeScript – Types
  • TypeScript – Union Types
  • TypeScript – String Literal Types
  • TypeScript – var, let and const
  • TypeScript – Template Strings
  • TypeScript – Arithmetic Operators
  • TypeScript – Logical Operators
  • TypeScript – Comparison Operators
  • TypeScript – ‘for…of’ Loop
  • TypeScript – Spread Operator
  • TypeScript – Arrays
  • TypeScript – Enums
  • TypeScript – Map
  • TypeScript – Set
  • TypeScript – Functions
  • TypeScript – Function Overloading
  • TypeScript – Transpiler
  • TypeScript – Truthy and falsy
  • TypeScript – == vs ===
  • TypeScript – undefined vs null
  • TypeScript – Variable Hoisting
  • TypeScript – tsconfig.json

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Sealed Classes and Interfaces