Skip to content

Instantly share code, notes, and snippets.

@gpsarkar
Created September 11, 2023 02:18
Show Gist options
  • Save gpsarkar/c59a0ccbc256c170900fddb24bf8531d to your computer and use it in GitHub Desktop.
Save gpsarkar/c59a0ccbc256c170900fddb24bf8531d to your computer and use it in GitHub Desktop.
tsconfig options

Important and Most Used:

  1. compilerOptions:

    • This section contains various options for controlling TypeScript compilation.
      • target: Specifies the ECMAScript target version (e.g., ES5, ES6, etc.).
      • module: Specifies the module system (e.g., CommonJS, ES6, etc.).
      • strict: Enables strict type checking options.
      • esModuleInterop: Ensures compatibility between CommonJS and ES module imports.
  2. include:

    • An array of file or directory patterns to include in the compilation process. Usually, this contains your TypeScript code.
  3. exclude:

    • An array of file or directory patterns to exclude from the compilation. Commonly, this includes folders like node_modules.
  4. extends:

    • Allows one tsconfig.json file to extend another. This is useful for sharing settings across multiple projects.

Less Common but Still Important:

  1. compilerOptions.lib:

    • Specifies the libraries that should be available at runtime. It's often set to "dom" for browser-related projects.
  2. compilerOptions.types:

    • Specifies the types that should be available for TypeScript to reference. This is useful for including external type definitions.
  3. compilerOptions.outDir:

    • Specifies the output directory for compiled files.
  4. compilerOptions.rootDir:

    • Sets the root directory of input files. TypeScript uses this to determine the original location of files for maintaining the directory structure in the output.

Less Common and More Specialized:

  1. compilerOptions.paths:

    • Allows you to specify module name mappings to different directories. Useful for module resolution and aliases.
  2. compilerOptions.noEmit:

    • Instructs TypeScript not to emit any output. This can be useful for projects that only need type checking.
  3. compilerOptions.declaration:

    • Generates corresponding .d.ts files for your TypeScript files. This is important when creating libraries or packages.
  4. compilerOptions.sourceMap:

    • Generates source maps which can be useful for debugging TypeScript code in the browser.
  5. compilerOptions.allowJs:

    • Enables TypeScript to process JavaScript files.

Less Common and Niche Use Cases:

  1. compilerOptions.noImplicitAny:

    • Flags an error if a variable has an implicit any type.
  2. compilerOptions.experimentalDecorators:

    • Enables support for experimental ECMAScript decorators.
  3. compilerOptions.noUnusedLocals / noUnusedParameters:

    • Flags unused local variables or parameters.
  4. compilerOptions.forceConsistentCasingInFileNames:

    • Ensures that file paths are consistently cased.
  5. compilerOptions.incremental:

    • Enables incremental compilation which can improve build times.
  6. compilerOptions.importHelpers:

    • Allows the import of helper functions from tslib.
  7. compilerOptions.baseUrl / paths:

    • Used for module resolution and aliases.
  8. compilerOptions.strictNullChecks:

    • Enables strict null checks, which helps catch common programming mistakes related to null and undefined.
  9. compilerOptions.noImplicitThis:

    • Flags an error when this is used in a context where it is assumed to have a certain type.
  10. compilerOptions.alwaysStrict:

    • Enables strict mode semantics in all files.
  11. compilerOptions.noFallthroughCasesInSwitch:

    • Flags an error for fallthrough cases in switch statements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment