Typescript. Exploring tsconfig.json

All options can be found in official documentation, so lets take a look on some of them. How to create tsconfig.json we have seen in previous post. As i understand tsconfig.json should be in the root directory. As result we will have something like this

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "sourceMap": true,
    "outDir": "out"
  },
  "exclude": [
    "node_modules"
  ],
  "include": [
    "src/scripts/**/*"
  ]
}

outDir is the directory where complied files will be.

Use files when therea are not many files, like this

{
  "compilerOptions": {},
  "files": [
    "core.ts",
    "sys.ts",
    "types.ts",
    "scanner.ts",
    "parser.ts",
    "utilities.ts",
    "binder.ts",
    "checker.ts",
    "tsc.ts"
  ]
}

but if there are many files in different directories it is better to use include like this

"include": [
    "src/scripts/**/*"
include and exclude support wildcard characters to make glob patterns:

* matches zero or more characters (excluding directory separators)
? matches any one character (excluding directory separators)
**/ matches any directory nested to any level
If a glob pattern doesn’t include a file extension, then only files with supported extensions are included (e.g. .ts, .tsx, and .d.ts by default, with .js and .jsx if allowJs is set to true).

Extends

Need to inherit configs and overwrite values like this, inherited all, except references

// configs/base.json:
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true
  }
}

// tsconfig.json
{
  "extends": "./configs/base",
  "files": ["main.ts", "supplemental.ts"]
}

// tsconfig.nostrictnull.json
{
  "extends": "./tsconfig",
  "compilerOptions": {
    "strictNullChecks": false
  }
}

realative paths will be relative to the files where they are.

References

Need to split project on pieces. More details by link

To be continued….

tsconfig.json with comments in Russian

This entry was posted in Без рубрики. Bookmark the permalink.