Updated Nov 29, 2026

11 - tsconfig and Tooling

📋 Jump to Takeaways

🎁 go build just works. TypeScript gives you a compiler, a config file with 50 options, and a separate runtime tool — all of which interact. Here's the minimal setup that actually makes sense for a Node.js backend.

Go gives you go build. TypeScript gives you tsconfig.json and a pile of tools you wire together yourself. Here's how to set it up.

tsconfig.json: The Compiler Config

Every TypeScript project has a tsconfig.json at the root. Here's a solid default for a Node.js backend:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "outDir": "dist",
    "rootDir": "src",
    "declaration": true,
    "sourceMap": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "isolatedModules": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "dist"]
}

Here's what matters.

strict: true

Never turn this off. It catches real bugs.

// strictNullChecks: catches null/undefined access
function greet(name: string | null) {
  console.log(name.toUpperCase());
  // Error: 'name' is possibly 'null'
}

// noImplicitAny: forces you to type things
function process(data) {
  // Error: Parameter 'data' implicitly has an 'any' type
}

// strictFunctionTypes: catches contravariance bugs
type Handler = (e: Event) => void;
const handler: Handler = (e: MouseEvent) => {};
// Error: Type '(e: MouseEvent) => void' is not assignable

Here's what strict mode enables:

Flag What It Does
strictNullChecks null and undefined are distinct types
noImplicitAny No implicit any on untyped variables
strictFunctionTypes Correct function type variance
strictBindCallApply Type-check bind, call, apply
strictPropertyInitialization Class properties must be initialized
noImplicitThis No implicit any for this
alwaysStrict Emit "use strict" in every file
useUnknownInCatchVariables catch variable is unknown, not any

Turning off strict is like disabling all your linters. You can. You shouldn't.

target, module, moduleResolution

These three work together. Get one wrong and you'll get confusing errors.

target: What JS version to emit. ES2022 is safe for Node 18+. It gives you top-level await, cause on errors, and Array.at().

"target": "ES2022"

module: What module system the output uses. NodeNext follows Node.js rules: ESM if package.json has "type": "module", CJS otherwise.

"module": "NodeNext"

moduleResolution: How TypeScript finds imported modules. NodeNext matches Node.js resolution behavior. Use it with "module": "NodeNext".

"moduleResolution": "NodeNext"

If you see "module": "commonjs" with "moduleResolution": "node", that's the old CJS setup. It works, but it's legacy config.

Running TypeScript

TypeScript doesn't run directly. You have options.

Compile First with tsc

The traditional approach. Compile to JS, then run the JS.

npx tsc                    # compile everything
node dist/index.js         # run the output

tsx: Run Directly

tsx uses esbuild to run TypeScript directly. Fast, no config.

npx tsx src/index.ts       # run directly
npx tsx watch src/index.ts # watch mode with auto-restart

This is what you want for development. Closest thing to go run main.go.

ts-node

Older, slower, more config. tsx has mostly replaced it.

npx ts-node src/index.ts

For production, compile with tsc and run the JS output. For development, use tsx.

The npm Ecosystem

npm will feel fragmented compared to Go's single toolchain. Here's the map.

package.json Scripts

Your Makefile. Define commands in package.json:

{
  "scripts": {
    "dev": "tsx watch src/index.ts",
    "build": "tsc",
    "start": "node dist/index.js",
    "lint": "eslint src/",
    "test": "vitest"
  }
}
npm run dev    # runs tsx watch src/index.ts
npm run build  # runs tsc
npm test       # shorthand for npm run test

npm vs npx

npm install adds packages. npx runs a package binary without installing it globally.

npm install express        # add to project
npx tsc --version          # run tsc from node_modules/.bin
npx tsx src/index.ts       # run tsx without global install

Lockfiles

package-lock.json (npm) or pnpm-lock.yaml (pnpm) pins exact dependency versions. Always commit it.

npm ci  # install from lockfile exactly (use in CI)
npm i   # install and update lockfile (use in dev)

ESLint for TypeScript

ESLint is the standard linter. @typescript-eslint adds type-aware rules.

npm install -D eslint @eslint/js typescript-eslint

Create eslint.config.js:

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.recommended,
  {
    rules: {
      "@typescript-eslint/no-unused-vars": ["error", {
        argsIgnorePattern: "^_"
      }],
      "@typescript-eslint/no-explicit-any": "error"
    }
  }
);
npx eslint src/

This catches things TypeScript doesn't: unused variables, any usage, inconsistent patterns.

Declaration Files (.d.ts)

A .d.ts file contains only type information. No runtime code. Think of it as a header file.

You hit them in two situations.

Third-party type packages. Many npm packages are written in JS and ship types separately.

npm install express
npm install -D @types/express

@types/express is a .d.ts file that tells TypeScript what express exports. Without it, import express from "express" is any.

Your own library output. Set "declaration": true in tsconfig and tsc generates .d.ts files alongside your JS output.

// src/math.ts
export function add(a: number, b: number): number {
  return a + b;
}
// dist/math.d.ts (generated)
export declare function add(a: number, b: number): number;

Consumers of your library get type checking without needing your source code.

Monorepo Basics

When your project grows, you split it into packages. npm and pnpm both support workspaces.

// root package.json
{
  "name": "my-monorepo",
  "workspaces": ["packages/*"]
}
my-monorepo/
├── package.json
├── packages/
│   ├── api/
│   │   ├── package.json
│   │   ├── tsconfig.json
│   │   └── src/
│   ├── shared/
│   │   ├── package.json
│   │   ├── tsconfig.json
│   │   └── src/
│   └── worker/
│       ├── package.json
│       ├── tsconfig.json
│       └── src/

Each package has its own tsconfig.json. They reference each other with TypeScript project references:

// packages/api/tsconfig.json
{
  "compilerOptions": { /* ... */ },
  "references": [
    { "path": "../shared" }
  ]
}
npm install  # installs all workspace dependencies
npx tsc -b   # builds all packages in dependency order

More manual wiring than Go modules. pnpm handles this better than npm if you go this route.

Key Takeaways

  • Start every project with strict: true. It catches real bugs that you'd otherwise find in production.
  • Use "target": "ES2022", "module": "NodeNext", "moduleResolution": "NodeNext" for modern Node.js backends.
  • Use tsx for development (fast, no config) and tsc + node for production.
  • package.json scripts are your Makefile. npm ci for CI, npm install for dev.
  • ESLint with @typescript-eslint is your linter. Set it up early.
  • .d.ts files provide types for JS packages. Install @types/* packages when the library doesn't bundle its own types.
  • Monorepos use workspaces and project references. Start simple, add structure when you need it.

🎁 You've seen the language in isolation — now what does TypeScript look like in a real production codebase? Middleware chains, dependency injection, branded types, and the patterns senior engineers reach for without explaining.

📝 Ready to test your knowledge?

Answer the quiz below to mark this lesson complete.

Spot something off? Report an issue