2 Minutes Read
By @akash_dathan
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 thedist
folder to your server along with package.json to installPROD
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"]