The only TsConfig you will ever need for backend πŸ™Œ
Blog / The only TsConfig you will ever need for backend πŸ™Œ
2 Minutes Read
By @akash_dathan

The only TsConfig you will ever need for backend πŸ™Œ

TsConfig is used to configure how typescript behaves in your project, lets see which is the most optimal way to configure it.

Here’s the config which you can just copy and paste to your project, scroll down for the explanations regarding each configuration.

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  },
  "include": ["src/**/*"],
  "exclude": ["**/*.test.ts"]
}


Lets deep dive into each config

  • dist is where your transpiled code go, in your CD you only need to copy the dist folder to your server along with package.json to install PROD dependencies.
"outDir": "./dist"
  • src is the root folder for your TS code
"rootDir": "./src"
  • Following are some strict checks, which will help you in the long run
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
  • Decorators, one of the best features of Typescript. most of the awesome frameworks use this, like NestJs, TypeOrm, ClassValidator, RoutingControllers, etc. Use the following config to enable decorators
"emitDecoratorMetadata": true,
"experimentalDecorators": true
  • Includes the files under src directory
"include": ["src/**/*"]
  • Excludes the tests, provide a regex for your test file pattern. Tests are run as TS files before transpiling, we don’t need tests after the transpiration.
"exclude": ["**/*.test.ts"]