Codectionary / Developer documentation / TypeScript

tsconfig.json Basics

tsconfig.json configures how the TypeScript compiler behaves for a project - which files to include, what JavaScript version to target, and which type-checking rules to enforce. It is the first file the compiler looks for when run without explicit file arguments.

Syntax

{ "compilerOptions": { }, "include": [], "exclude": [] }

Examples

A Typical Configuration

Common compiler options for a modern web project.

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "outDir": "./dist"
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "dist"]
}

Extending a Base Config

Sharing configuration across multiple projects or packages in a monorepo.

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "outDir": "./dist/app" // overrides just this one option from the base config
  }
}

Best practices

  • Enable "strict": true in every new project - it turns on the full set of TypeScript's strictness checks together, catching significantly more bugs
  • Set "target" based on the actual JavaScript environments your code needs to run in, not necessarily the newest possible version
  • Use "skipLibCheck": true in most projects to skip type-checking of .d.ts files in node_modules, meaningfully speeding up compilation
  • Use "extends" to share a common base configuration across multiple packages in a monorepo, overriding only what genuinely differs per package

At a glance

Purpose
Static types for JavaScript
File extension
.ts ยท .tsx
Runs in
Compiled to JavaScript
Usually used with
JavaScript and its ecosystem

Specifications & further reading

Related TypeScript documentation

Strict Mode Options
The "strict" tsconfig option is actually a shorthand that enables a whole family of individual strictness flags at once, including strictNullChecks (null/undefined are not assignable to other types by default), noImplicitAny (variables must have an inferable or explicit type), and strictFunctionTypes. Enabling strict mode is one of the highest-value changes for TypeScript's type safety.
Declaration Files (.d.ts)
Declaration files contain only type information, no actual implementation - they describe the shape of existing JavaScript code so TypeScript can type-check against it. This is how you get autocomplete and type safety for plain JavaScript libraries, and how your own TypeScript library can ship types alongside its compiled JavaScript output.
Interfaces
Interfaces in TypeScript define the structure of objects by specifying property names and their types. They act as contracts that ensure objects conform to specific shapes, providing type safety and better IDE support. Interfaces can be extended, merged, and used to type-check function parameters, return values, and object literals.
Basic Types
TypeScript extends JavaScript with static types, letting the compiler catch type errors before code ever runs. Beyond the familiar string, number, and boolean, TypeScript adds any (disables checking entirely), unknown (a safer any that requires narrowing), void (a function returning nothing), and never (a value that can never occur, like a function that always throws).