Skip to content

TSConfig File

Peter edited this page Apr 2, 2016 · 1 revision

tsconfig.json

A unified project format for TypeScript (see merged PR on Microsoft/TypeScript). The TypeScript compiler (1.5 and above) only cares about compilerOptions and files. TypeScript 1.6 introduced the exclude property. We add additional features to this with the typescript team's approval to extend the file as long as we don't conflict.

tsconfig.json is great for building the "compilation context" so you don't need to use /// <reference comments.

Basic

The minimal tsconfig.json file you need is:

{}

i.e. an empty JSON file at the root of your project ❤️ This will be sufficient for most people.

If you open a new project folder from CATS (Project -> Open Project...) and it cannot find any tsconfig file, this basic file will be created by default.

CATS will look for the tsconfig files that match the following pattern: tsconfig*.json

So if you want you can have more than one tsconfig file in the same directory by for example using tsconfig-server.json and tsconfig-client.json for the two different TypeScript projects.

Options

  • compilerOptions: similar to what you would pass on the commandline to tsc.
  • exclude: To exclude directories or files from being referenced. This accepts files or folders. This does not accept glob formatting.
  • filesGlob: To make it easier for you to just add / remove files in your project we add filesGlob which accepts an array of glob / minimatch / RegExp patterns (similar to grunt) to specify source files.
  • formatCodeOptions : Code formatting options
  • compileOnSave : Should AtomTS compile on save
  • buildOnSave : Should AtomTS build on save
  • formatOnSave which will format the Typescript file on save.

Examples

exclude

These references are relative to the tsconfig.json path. This does not accept glob formatting.

NOTE: exclude should not be used when files or filesGlob are in use. The presence of the files property takes presedence over the exclude property. Read about it in the TypeScript wiki.

{
     "exclude": [
       "node_modules",
       "bower_components",
       "lib/libFileToExclude.d.ts"
     ]
}

filesGlob

Note: files is kept up to date by expansion of filesGlob. This is because files is standard across all IDEs vs. filesGlob is specific to atom-typescript.

A default filesGlob is available for you as a snippet : fg

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "noLib": false
    },
    "filesGlob": [
        "**/*.ts",
        "**/*.tsx",
        "!node_modules/**"
    ],
    "files": [
        "globals.ts",
        "linter.ts",
        "main/atom/atomUtils.ts",
        "main/atom/autoCompleteProvider.ts",
        "worker/messages.ts",
        "worker/parent.ts"
    ]
}

formatCodeOptions

These are used when you request the IDE to format TypeScript code.

{
    "formatCodeOptions": {
        "indentSize": 4,
        "tabSize": 4,
        "newLineCharacter": "\r\n",
        "convertTabsToSpaces": true,
        "insertSpaceAfterCommaDelimiter": true,
        "insertSpaceAfterSemicolonInForStatements": true,
        "insertSpaceBeforeAndAfterBinaryOperators": true,
        "insertSpaceAfterKeywordsInControlFlowStatements": true,
        "insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
        "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
        "placeOpenBraceOnNewLineForFunctions": false,
        "placeOpenBraceOnNewLineForControlBlocks": false
    }
}

compileOnSave

We highly recommend you leave it as the default (true). But if you want you can can disable compile on save from IDEs. This allows you to leave the compilation to external tools. Discussion

buildOnSave

Build means compile all files. Useful if for some reason you are using --out. Default is false. Note that build is a slow process, therefore we recommend leaving it off. But in case this is the way you want to go its there for your convenience.

{
  "buildOnSave": true
}

atom

Configuration options specific to Atom.

formatOnSave

Setting this to true will format the entire file exactly like ctrl+alt+l or cmd+alt+l does on save. (this defaults to false)

{
  "atom": {
    "formatOnSave": true
  }
}

Additional Notes

FWIW a json schema is also available