Permalink
153 lines (124 sloc) 6.2 KB

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.

Options

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

scripts

Inspired by project.json : https://github.com/aspnet/Home/wiki/Project.json-file#scripts. We only support postbuild at the moment.

{
  "scripts": {
    "postbuild": "echo after building"
  }
}

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.

rewriteTsconfig

Atom-Typescript constantly resolves the filesGlob listed in your tsconfig.json to ensure that the glob is in sync with your project. If your project doesn't require this (you are managing your filesGlob some other way), set this to false (this defaults to true).

{
  "atom": {
    "rewriteTsconfig": true
  }
}

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