Skip to content

Instantly share code, notes, and snippets.

@adriancmiranda
Forked from er-ant/tsconfig-all.js
Created December 17, 2023 18:51
Show Gist options
  • Save adriancmiranda/e92e6f7ebc79d61d52956b5486fb27ee to your computer and use it in GitHub Desktop.
Save adriancmiranda/e92e6f7ebc79d61d52956b5486fb27ee to your computer and use it in GitHub Desktop.
tsconfig.json with comments and explanations
{
// Config for IDE to reload
"compileOnSave": true,
"exclude": [
// Specifies an array of filenames or patterns that should be skipped when resolving include.
// Default:
// ["node_modules", "bower_components", "jspm_packages"], plus the value of outDir if one is specified.
"**/*.spec.ts",
"node_modules"
],
"include": [
// Specifies an array of filenames or patterns to include in the program.
// Usually this config is empty.
// Default:
// [] if files are specified, otherwise ["**/*"]
],
// The value of extends is a string which contains a path to another configuration file to inherit from. The path may use Node.js style resolution.
"extends": "../tsconfig-base.json",
"files": [
// Specifies an allowlist of files to include in the program.
// If empty takes all files
// Default:
// false
"core.ts",
"sys.ts"
],
"references": [
// Helps to organize applications splitted in smaller modules
// https://stackoverflow.com/questions/51631786/how-to-use-project-references-in-typescript-3-0
{ "path": "../src" }
],
"typeAcquisition": {
// Provides default typings from DefinitelyTyped library for js libraries in node_modules
// Create jsconfig.json in the root of your project with some of next configs if you want to customize it.
"include": ["jest"],
"exclude": ["jquery"]
},
"compilerOptions": {
/* Most important and used TS compiler options */
"allowJs": false, // allow to import js files in your projects, usefull when you import js libs in your project
"allowUmdGlobalAccess": false, // Allolw UMD exports as global, when they are not available in runtime
"baseUrl": "./src", // base directory to resolve all module and file names from
"emitDecoratorMetadata": true, // support for types in metadata for decorators, Angular important
"experimentalDecorators": true, // support for types in decorators, Angular important
"importHelpers": false, // imports some operations from "tslib", instead of creation them in each file where are they used
"module": "CommonJS", // JS module system, values: "ES2020" | "None" | "UMD" | "AMD" | "System" | "ESNext", list with examples: https://www.typescriptlang.org/tsconfig#module
"moduleResolution": "node", // module resolution strategy, 'node' | 'classic', classic is for TS < 1.6
"noEmit": false, // do not create JS output files
"outDir": "n/a", // where put transpiled JS files, without value puts in same folder with TS files
"outFile": "n/a", // bundle file with all concatenated JS files
"plugins": [], // plugins for IDE to parse your code better
"resolveJsonModule": false, // include json files by default in your project as a module
"sourceMap": false, // enables generation of source maps - files allow debuggers and other tools to analyze your code
"target": "es3", // which EcmaScript version should tsc follow when transpiles your files, if no limitations prefer to use latest versions, values: es3, es5, es6 ,esnext, es2020
"types": ["node", "jest", "express"], // if specified, includes only listed lists of types
"typeRoots": [
// All @types packages are usually visible for your project, specify which types to include
"node_modules/@types"
],
"lib": [
// List of imported libraries required for your project, full list: https://github.com/microsoft/TypeScript/tree/main/src/lib
// You can specify them for your platform (browser/not a browser), EcmaScript Versions and etc
"es2018",
"es6"
],
"paths": {
// Map of urls for easier imports
"modules/*": ["app/modules/*"],
"environment/*": ["environments/*"]
},
/* End Most important and used TS compiler options */
/* Build options - options mainly for build stage to change behaviour of project compilation */
"declaration": false, // generate declaration file.d.ts files after transpilation TS -> JS
"declarationMap": false, // generate source-map files so IDE can work with original TS file
"declarationDir": "n/a", // configure root directory for declaration files
"emitDeclarationOnly": false, // emit d.ts files for a js file, do not emit JS files
"inlineSourceMap": false, // instead of .js.map with js file, puts .js.map content into .js file
"inlineSources": false, // put .ts sources inside with compiled js, requires sourceMap or inlineSourceMap
"mapRoot": ".", // path for debugger with sourcemaps
"sourceRoot": "https://my-website.com/debug/source/", // path for debugger with source code
"downlevelIteration": false, // transpilation TS -> JS generates older JS versions
"emitBOM": false, // flag to write UTF-8 Byte Order Mark
"isolatedModules": false, // helps to resolve imports for single file builders like Babel
"newLine": "CRLF", // End of line type in bundle files
"noEmitHelpers": false, // do not put helpers in result bundle files
"noEmitOnError": false, // do not create build results, if any errors were reported. Helps in dev-watch mode
"noImplicitUseStrict": false, // disable default 'use strict' in every file
"noLib": false, // do not include libs and provide your own types
"noResolve": false, // do not add "/// <reference path="..." />" in bundle results files
"preserveConstEnums": false, // do not transpile const enum to values and include in result code them, browser compatibility
"removeComments": false, // removes comments from your TS codebase when TS -> JS
/* End Build Options */
/* Codestyles - how to make your TS code more static typed and improve its quality */
"alwaysStrict": false, // 'use strict' for all files, recommend to turn on
// Start strict typechecks
"strict": false, // turn on next flags, recommend to turn it on for better code quality:
"noImplicitAny": false, // error when no type provided
"noImplicitThis": false, // keep 'this' pointed to the class or with provided type
"strictBindCallApply": false, // typecheck for bind, call and apply methods
"strictFunctionTypes": false, // typecheck for function parameters mor rigorous
"strictNullChecks": false, // typecheck for null and undefined to avoid bugs
"strictPropertyInitialization": false, // strict check for value initialization of the class property
// End strict typechecks
"noFallthroughCasesInSwitch": false, // check switch for break and return
"noImplicitReturns": false, // check if all code parts return value
"noPropertyAccessFromIndexSignature": false, // provide consistency for obj.key & obj["key"], since 4.2
"noUncheckedIndexedAccess": false, // add undefined to unknown properties defined in [propName: string]: string;, since 4.1
"noUnusedLocals": false, // report errors on not used variables
"noUnusedParameters": false, // report errors on not used function params
"noStrictGenericChecks": false, // typcheck for generics
"allowUnreachableCode": undefined, // report unreachable code, undefined - editor, true - allow, false - raise error
"allowUnusedLabels": false, // do not allow to write labels in JS
"forceConsistentCasingInFileNames": false, // returns error, when program is trying to load file in wrong case (upper or lower for example)
/* End Codestyles */
/* Compiler options - less popular */
"checkJs": false, // works together with allowJS, if enabled reports JS code errors
"assumeChangesOnlyAffectDirectDependencies": false, // check only changed files, not the entire project if true
"disableSizeLimit": false, // disable size limit for project
"importsNotUsedAsValues": "remove", // save or delete imports used for types only, values: 'remove' | 'preserve' | 'error'
"maxNodeModuleJsDepth": 0, // The maximum dependency depth to search under node_modules and load JavaScript files, with allowJs
"skipLibCheck": false, // skip typecheck for declaration files
"allowSyntheticDefaultImports": false, // allow imports from modules without default exports
"esModuleInterop": false, // recommended: true, create helpers (__importDefault and etc) to parse CommonJS/AMD/UMD modules correct and follow specs, enables allowSyntheticDefaultImports
"preserveSymlinks": false, // same with NodeJS and Webpack, resolves relative to the location of the symbolic link file
"useDefineForClassFields": false, // TODO
"suppressExcessPropertyErrors": false, // disable excess property error in classes
"suppressImplicitAnyIndexErrors": false, // turn off any checks for objects indexed like this: obj["foo"]
/* End Compiler options - less popular */
/* React TS Configs */
"jsx": undefined, // controls how to transpile TSX -> JS: "react" | "react-jsx" | "react-jsxdev" | "preserve" | "react-native"
"jsxFactory": "React.createElement", // factory function to use when compiling TSX functions, possible vallues: 'h' | 'preact.h'
"jsxFragmentFactory": undefined, // Specify the JSX fragment factory function to use when targeting react JSX emit with jsxFactory compiler option is specified, since 4.0
"jsxImportSource": "react", // module to use when declare jsx/tsx , since 4.1
/* End React TS Configs */
/* Verbose build process */
"explainFiles": false, // verbose files transpilation, explain files transpilation, since 4.2
"extendedDiagnostics": false, // verbose files transpilation, show wasted time
"generateCpuProfile": "profile.cpuprofile", // verbose files transpilation, analyze CPU
"listEmittedFiles": false, // verbose files transpilation, list filenames transpiled
"listFiles": false, // verbose files transpilation, print names of files part of the compilation
"traceResolution": false, // verbose files transpilation, track why module is not included in final bundle
/* End Verbose build process */
/* Library configs - these configs can be helpful in big projects or libraries */
"composite": true, // used together with references from root settings, if you provide ref, ref module must turn on composite
"incremental": true, // if composite is on, then false; creates .tsbuildinfo file with info about last project compilation
"tsBuildInfoFile": ".tsbuildinfo", // stores information about TS compilation, as a part of composite projects
"disableReferencedProjectLoad": false, // should TS load the entire projects in memory or not, since 4.0
"disableSolutionSearching": false, // composite projects, IDE integration to avoid find all references in the project
"disableSourceOfProjectReferenceRedirect": false, // composite projects, use .d.ts files for boundaries between modules
"rootDir": "../src", // does not affect which files become part of the compilation, path to the folder where should TSC start looking for your files
"rootDirs": ["src/views", "generated/templates/views"], // runtime, to create virtual tree of directories, usefull for libraries
/* End Library configs */
},
// Angular TS configs: https://angular.io/guide/angular-compiler-options
"angularCompilerOptions": {
"strictInjectionParameters": false, // generate all possible files even if they are empty
"annotationsAs": , // TODO
"annotateForClosureCompiler": false, // Tsickle to annotate JS for Closure Compiler
"disableExpressionLowering": true, // allow code from annotations to be imported from modules
"disableTypeScriptVersionCheck": false, // doesn't report if wrong TS version is used
"enableI18nLegacyMessageIdFormat": true, // use old algorithm of ids for i18n translations
"enableIvy": true, // true since NG9
"enableResourceInlining": false, // replaces replaces the templateUrl and styleUrls property in all @Component decorators with inlined contents in template and styles properties
"enableLegacyTemplate": false, // enables use of the <template> element instead of <ng-template>
"flatModuleOutFile": "libname.js", // to create flat modules packaged similarly to @angular/core, package.json for the library should refer to the generated flat module index instead of the library index file
"flatModuleId": "libname", // id to use for the module above
"generateCodeForLibraries": true, // generates factories for .d.ts files
"preserveWhitespaces": false, // removes blank text nodes from compiled templates
"skipMetadataEmit": false, // turn off producing .metadata.json, which contains info for template compiler
"skipTemplateCodegen": false, // does not emit .ngfactory.js and .ngstyle.js files
"strictMetadataEmit": false, // check errors in .metadata.json
/* Codestyle */
"fullTemplateTypeCheck": false, // provides template typechecking
"strictInjectionParameters": false, // typecheck for injections
"strictTemplates": false, // typecheck for template
"strictInputAccessModifiers": false, // typecheck for input modifiers
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment