tsconfig.json

Image of Author
October 17, 2022 (last updated September 18, 2024)

The tsconfig.json file is a top-level file found in TypeScript projects. One of it's primary purposes is configuring the TypeScript compiler, tsc.

Module resolution: bundle and preserve, or, how to avoid .js extensions in your .ts imports

https://www.typescriptlang.org/tsconfig/#preserve

https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler

// tsconfig.json
{
  "compilerOptions": {
    "module": "Preserve",
    "moduleResolution": "Bundler"
  }
}

"Preserve" essentially tells tsc to do a pass-through of module imports, i.e., preserve the imports as they are written. One intent of this is because your module resolution strategy is to use a bundler which will handle resolution for you. This is achieved with "Bundler".

In a nodejs environment they combine nicely to enable you to avoid having to append .js to your imports, especially when they are actually .ts files before compilation!

allow any

In early stages of developing software you might want to write exploratory code without getting compiler warnings about any types. This includes both implicit and explicit anys

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noExplicitAny": false
  }
}

Problem: React is a UMD global....

Solution:

{
  "compilerOptions": {
    "allowUmdGlobalAccess": true
  }
}

tsconfig#allowUmdGlobalAccess docs