Basics

Challenges

Classes

Cookies

Debugging

Events

External Files

Flow Control

Forms

Functions

Html Elements

Installation

Interfaces

Keywords

Modules

Namespaces

Operators

Reference Files

String

Types

TypeScript - tsconfig

The presence of a tsconfig.json file in a directory indicates that the directory is the root of a TypeScript project. This is also known as a TypeScript Project File. The tsconfig.json file specifies the files to included and excludes, where to compile to, and the compiler options required to compile the project.

By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain.

tsconfig.json, aka the Project File, also supports configuration inheritance.

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

With the right set of arguments, you can determine the inclusion or exclusion of files. You can determine which selected ts files will be compiled (or all) and where the outputs will be; whether one js file per ts file or all into one js file.


{
    "compilerOptions": {
    "module": "commonjs",
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true
    },
    "files": [
    "HelloWorld.ts",
    ]
}

// Another Example
{
    "compilerOptions": 
    {
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "target": "es6",
        "outFile": "javascripts/app.js",    // <-- combine into one file
        //"outDir" : "/javascripts/" // <-- dir where ts files will be compiled into. One for each ts file.
                                            }
                                            }

Tips

1) To see att the compiler options available for tsconfig, you can type tsc -h for help.

2) You can use tsc to create a starter Project File by using this command from a command prompt in the root of your project folder. It will give you all available options.

tsc --init

3) You will need to use the command terminate to tell tsc to stop watching your tsc if you make changes to it. ctrl + shift + p >> terminate. Rebuilding it will make it start watching your config file again if it is set up to do so.

4) When trying to include or exlude certain files using patterns, keep these wildcards in mind:

  • * matches zero or more characters (excluding directory separators)
  • ? matches any one character (excluding directory separators)
  • **/ recursively matches any subdirectory

Helpful links: