TS Config (tsconfig.json)
Popular Options
target(ECMAScript Target Version):Description: Sets the ECMAScript target version for the compiled JavaScript.
Popular Use:
"target": "es6"or higher (like"es2018") to leverage newer ECMAScript features that are supported in modern environments.
module(Module System):Description: Determines the module system used in the project.
Popular Use:
"module": "commonjs"for Node.js projects or"module": "esnext"for projects that leverage modern module syntax (like ECMAScript modules).
strict(Enable All Strict Type-Checking Options):Description: Enables all strict type-checking options.
Popular Use:
"strict": trueto ensure a more rigorous type-checking, which can catch more potential errors at compile time.
esModuleInterop(ES Module Interop):Description: Enables compatibility with Babel-imported ECMAScript modules.
Popular Use:
"esModuleInterop": trueto allow default imports from modules without a default export. This is more aligned with the current ECMAScript module system.
outDir(Output Directory):Description: Specifies the output directory for the compiled JavaScript files.
Popular Use:
"outDir": "./dist"to keep the source code and compiled code in separate directories, maintaining a clean project structure.
sourceMap(Generate Source Maps):Description: Enables the generation of source maps, which help in debugging the compiled JavaScript by mapping it back to the original TypeScript code.
Popular Use:
"sourceMap": truefor development environments to aid in debugging.
noImplicitAny(Disallow ImplicitanyTypes):Description: Raises errors on expressions and declarations with an implied
anytype.Popular Use:
"noImplicitAny": trueto avoid variables with theanytype unless explicitly declared, leading to safer and more predictable code.
moduleResolution(Module Resolution Strategy):Description: Determines how modules get resolved.
Popular Use:
"moduleResolution": "node"for Node.js projects or"moduleResolution": "classic"for web projects.
jsx(JSX Support):Description: Specifies the JSX code generation style:
'preserve','react-native', or'react'.Popular Use:
"jsx": "react"for projects using React. It converts JSX syntax to JavaScript that React understands.
includeandexclude(File Inclusion/Exclusion in Compilation):Description: Specifies a list of files or patterns to include or exclude from the compilation.
Popular Use:
jsonCopy code"include": ["src/**/*"], "exclude": ["node_modules", "**/*.spec.ts"]to include all files in the
srcdirectory while excludingnode_modulesand test files.
lib(Library Files to be Included in the Compilation):Description: Specifies a list of library files to be included in the compilation.
Popular Use:
["dom", "es6", "dom.iterable", "scripthost"]for web projects, including types for DOM and ECMAScript features.
allowJs(Allow JavaScript Files to be Compiled):Description: Allows JavaScript files to be compiled along with TypeScript files.
Popular Use:
"allowJs": truein projects where you are gradually migrating from JavaScript to TypeScript.
skipLibCheck(Skip Type Checking of Declaration Files):Description: Skips type checking of all declaration files (
.d.tsfiles).Popular Use:
"skipLibCheck": truecan speed up the compile time, especially in large projects, but at the cost of potentially missing some types inconsistencies in third-party libraries.
forceConsistentCasingInFileNames(Force Consistent Casing in File Names):Description: Ensures that the casing of referenced file names is consistent during the compile.
Popular Use:
"forceConsistentCasingInFileNames": trueto avoid issues on case-sensitive file systems.
Additional Options
noEmit(Do Not Emit Outputs):Description: Prevents the compiler from generating output files like JavaScript source code or
.d.tsdeclaration files.Popular Use:
"noEmit": trueis often used in projects where TypeScript is used only for type checking, such as in some frontend projects where a different build tool is responsible for generating the final JavaScript.
noEmitOnError(No Emit on Error):Description: Ensures no output files are generated if any errors are reported.
Popular Use:
"noEmitOnError": trueis useful to ensure that builds do not proceed with errors, which is particularly important in CI/CD pipelines.
strictNullChecks(Strict Null Checking):Description: When enabled,
nullandundefinedare only assignable to their own types andany.Popular Use:
"strictNullChecks": trueis crucial for robust type checking, helping to avoid common bugs related to null references.
noImplicitReturns(No Implicit Returns in Functions):Description: Ensures that all code paths in a function explicitly return a value.
Popular Use:
"noImplicitReturns": trueis used to improve code readability and maintainability by making return patterns explicit.
noUnusedLocalsandnoUnusedParameters(No Unused Variables and Parameters):Description: Report errors on unused local variables and function parameters.
Popular Use:
"noUnusedLocals": trueand"noUnusedParameters": trueare helpful in maintaining clean code, free from unused or redundant code.
resolveJsonModule(Import JSON Modules):Description: Allows importing
.jsonfiles directly in TypeScript files.Popular Use:
"resolveJsonModule": trueenables working with JSON files just as you would with TypeScript modules, which can be particularly useful when dealing with configuration files or data.
isolatedModules(Transpile Each File as a Separate Module):Description: Ensures each file can be safely transpiled without relying on the types from other files.
Popular Use:
"isolatedModules": trueis often used in projects where the code needs to be compatible with transpilers like Babel.
downlevelIteration(More Accurate Iteration Support):Description: Provides more accurate support for iterating ES2015 structures in downleveled versions of ECMAScript.
Popular Use:
"downlevelIteration": trueis useful when targeting older ECMAScript standards but still wanting to use newer syntax likefor...ofloops over new types likeSetorMap.
composite(Project References):Description: Enables project references, allowing TypeScript to use builds from other projects.
Popular Use:
"composite": trueis used in larger projects or monorepos where you want to split your code into multiple TypeScript projects and reference them.
incremental(Enable Incremental Compilation):Description: Allows TypeScript to save information about the project graph from the last compilation to speed up subsequent compilations.
Popular Use:
"incremental": truesignificantly improves the build times in larger projects by only recompiling what's necessary.
baseUrlandpaths(Base URL and Path Mapping):Description:
baseUrlsets the base directory for non-relative module names.pathsspecifies a series of entries that re-map imports to lookup locations relative to thebaseUrl.
Popular Use:
"baseUrl": "."and definingpathsare commonly used to set up custom path aliases, making imports cleaner and more manageable, especially in large projects.
Last updated