Affiliate link
TypeScript - tsconfig.json
To configure the TypeScript compiler, create a file called tsconfig.json. This file is used to configure the TypeScript compiler what files to include or exclude, what target version of ECMAScript to use, and how to handle various other settings.
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"outDir": "dist",
"sourceMap": true,
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}- compilerOptions: This is where you specify the compiler options for TypeScript. Some of the most commonly used options include:
- target: The ECMAScript version that the TypeScript code should be compiled to. For example, ES5, ES6, ES2015, ES2016, etc.
- module: The module format to use, such as commonjs, es2015, esnext, etc.
- outDir: The output directory where the compiled JavaScript files will be saved.
- sourceMap: Whether to generate source maps or not.
- strict: Enables strict type checking options, including noImplicitAny, strictNullChecks, and strictFunctionTypes.
- noImplicitAny: If true, TypeScript will throw an error if it cannot infer the type of a variable or parameter.
- esModuleInterop: If true, TypeScript will enable the interop between CommonJS and ES6 modules.
- include: This property is an array of file or directory paths that should be included in the compilation process.
- exclude: This property is an array of file or directory paths that should be excluded from the compilation process.
In this example, the TypeScript code will be compiled to ES2015 and using CommonJS modules. The compiled JavaScript files will be saved in the dist directory. Strict type checking is enabled so TypeScript throw an error if it cannot infer the type of a variable or parameter. All .ts files under the src directory will be included to compile, but excluding any files under the node_modules directory or any files ending in .spec.ts.
Affiliate link
Affiliate link




