Skip to content

base

npm version License: MIT Node.js TypeScript

> Base TypeScript configuration with strict type checking and modern defaults. Designed to be extended by projects without imposing file inclusion/exclusion patterns.

  • 🔒 Strict Mode: All strict flags enabled for maximum type safety
  • 🚀 Modern Defaults: ES2022 target with NodeNext module resolution
  • 🛡️ Extra Safety: Additional strict checks beyond the strict flag
  • 🎯 Flexible: No include/exclude defined - you control what gets compiled
  • 🗺️ Source Maps: Enabled by default for debugging
Terminal window
pnpm add -D @jmlweb/tsconfig-base typescript

> 💡 Upgrading from a previous version? See the Migration Guide for breaking changes and upgrade instructions.

Create a tsconfig.json file in your project root:

{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"composite": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}
{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"composite": true,
"declarationDir": "./dist"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"jsx": "react-jsx"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}

You can override any option in your project’s tsconfig.json:

{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"target": "ES2020",
"noUncheckedIndexedAccess": false
},
"include": ["src/**/*"]
}
OptionValueDescription
stricttrueEnables all strict type checking options
targetES2022Modern JavaScript features
moduleNodeNextNode.js ESM module system
moduleResolutionNodeNextNode.js module resolution
esModuleInteroptrueCommonJS/ESM interoperability
skipLibChecktrueSkip type checking of declaration files
forceConsistentCasingInFileNamestrueEnforce consistent file name casing
declarationtrueGenerate .d.ts files
declarationMaptrueGenerate sourcemaps for .d.ts files
sourceMaptrueGenerate sourcemaps for debugging
noUncheckedIndexedAccesstrueAdd undefined to index signatures
noImplicitOverridetrueRequire override keyword
noPropertyAccessFromIndexSignaturetrueRequire bracket notation for index signatures
exactOptionalPropertyTypestrueDifferentiate between undefined and optional
noFallthroughCasesInSwitchtrueReport fallthrough cases in switch
isolatedModulestrueEnsure compatibility with transpilers
verbatimModuleSyntaxtrueEnforce explicit type imports/exports
resolveJsonModuletrueAllow importing JSON files

Since this base config intentionally omits file patterns, you must configure:

  • include: Which files to compile (e.g., ["src/**/*"])
  • exclude: Which files to ignore (e.g., ["node_modules", "dist"])
  • outDir: Output directory for compiled files
  • rootDir: Root directory of source files (optional but recommended)

This base config intentionally omits include and exclude patterns because:

  • ✅ Different projects have different file structures
  • ✅ You maintain full control over what gets compiled
  • ✅ Prevents conflicts with project-specific patterns
  • ✅ More flexible for various project types

> Philosophy: TypeScript should catch bugs at compile time through strict type checking. If it compiles without errors, it should work correctly.

This package provides an opinionated TypeScript configuration that enables all strict flags and additional safety checks. It’s designed to prevent common JavaScript pitfalls through TypeScript’s type system while remaining flexible enough for any project type.

All Strict Flags Enabled (strict: true + extras): Enables strict null checks, no implicit any, strict function types, etc.

  • Why: TypeScript’s strict mode catches entire classes of bugs (null/undefined errors, implicit any holes, binding issues). Additional flags like noUncheckedIndexedAccess catch even more edge cases
  • Trade-off: More initial type errors when adopting, requires explicit null handling. But this prevents runtime crashes
  • When to override: For gradual migration from JavaScript (but aim to enable all flags eventually)

Modern Target (ES2022): Compiles to ES2022 with modern JavaScript features

  • Why: Modern Node.js and browsers support ES2022. Using modern features provides better performance and cleaner output. Let your runtime handle the code
  • Trade-off: Requires Node.js 18+ or modern browsers. If targeting older environments, override with ES2020 or lower
  • When to override: When supporting legacy environments (but consider transpiling separately)

NodeNext Module Resolution: Uses Node.js ESM resolution algorithm

  • Why: Matches how Node.js resolves modules in real projects. Prevents module resolution mismatches between TypeScript and runtime
  • Trade-off: Requires proper package.json exports and file extensions in imports. But this matches modern JavaScript standards
  • When to override: For legacy projects using CommonJS exclusively (but you should migrate to ESM)

No File Inclusion: Doesn’t specify include or exclude patterns

  • Why: Different projects have different structures (src/, lib/, packages/). Config shouldn’t impose opinions about project layout
  • Trade-off: Must define your own include/exclude in project tsconfig.json (but you’d do this anyway for custom needs)
  • When to override: Never - add include/exclude in your project’s tsconfig.json

Source Maps Enabled: Generates source maps for debugging

  • Why: Source maps enable debugging TypeScript source in Node.js and browsers. Essential for production debugging
  • Trade-off: Slightly larger build output, but negligible compared to debugging benefits
  • When to override: If you’re absolutely certain you don’t need debugging (rare)

Use this configuration when you want:

  • ✅ Strict TypeScript type checking for maximum type safety
  • ✅ Modern JavaScript features (ES2022)
  • ✅ Node.js ESM module system
  • ✅ Flexible file inclusion/exclusion patterns
  • ✅ Foundation for extending with framework-specific configs

For React projects, use @jmlweb/tsconfig-react instead.

For internal tooling projects, use @jmlweb/tsconfig-internal instead.

{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler"
}
}
{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "node"
}
}
{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"noUncheckedIndexedAccess": false,
"exactOptionalPropertyTypes": false
}
}

TypeScript compilation is typically handled by your build tool or IDE. For manual compilation:

{
"scripts": {
"build": "tsc",
"typecheck": "tsc --noEmit"
}
}
  • Node.js >= 18.0.0
  • TypeScript >= 5.0.0

This package requires the following peer dependency:

  • typescript (>= 5.0.0)

See real-world usage examples:

  • TypeScript - Strongly typed programming language that builds on JavaScript
  • ts-node - TypeScript execution engine for Node.js
  • tsx - Fast TypeScript/ESM execution (alternative to ts-node)
  • ESLint - Linter for TypeScript (use with @jmlweb/eslint-config-base)

> Note: This section documents known issues and their solutions. If you encounter a problem not listed here, please open an issue.

Symptoms:

  • Error: “Relative import paths need explicit file extensions in ECMAScript imports”
  • Import statements like import { foo } from './bar' fail

Cause:

  • This config uses moduleResolution: "NodeNext" which follows Node.js ESM rules
  • Node.js requires explicit .js extensions in import statements (even for .ts files)

Solution:

Add .js extensions to your imports (TypeScript will resolve to .ts files):

// Before
import { foo } from './bar';
// After
import { foo } from './bar.js';

Or switch to a bundler-based module resolution:

{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler"
}
}

Symptoms:

  • Error: “Option ‘module’ must be set to ‘NodeNext’ when ‘moduleResolution’ is ‘NodeNext’”
  • Type errors related to module resolution

Cause:

  • Both module and moduleResolution must be set to compatible values
  • This config uses NodeNext for both

Solution:

If you need to override the module system, update both options together:

{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler"
}
}

Symptoms:

  • Code runs but module resolution is incorrect
  • require statements in output when you expected import

Cause:

  • Your package.json has "type": "module" but your build uses CommonJS
  • Or vice versa

Solution:

Match your package.json to your build output:

package.json
{
"type": "module" // For ESM output (this config's default)
}

Or override to CommonJS:

tsconfig.json
{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "node"
}
}

Symptoms:

  • Error: “Object is possibly ‘undefined’” when accessing object properties
  • Example: obj[key] shows type T | undefined

Cause:

  • This config enables noUncheckedIndexedAccess for extra safety
  • TypeScript correctly adds undefined to index access types

Solution:

Use optional chaining or explicit checks:

// Before
const value = obj[key].toString();
// After - option 1: optional chaining
const value = obj[key]?.toString();
// After - option 2: explicit check
if (obj[key] !== undefined) {
const value = obj[key].toString();
}
// After - option 3: type assertion (use sparingly)
const value = obj[key]!.toString();

Or disable this strict check:

{
"extends": "@jmlweb/tsconfig-base",
"compilerOptions": {
"noUncheckedIndexedAccess": false
}
}

> Note: If no breaking changes were introduced in a version, it’s safe to upgrade without additional steps.

No breaking changes have been introduced yet. This package follows semantic versioning. When breaking changes are introduced, detailed migration instructions will be provided here.

For version history, see the Changelog.

Need Help? If you encounter issues during migration, please open an issue.

See CHANGELOG.md for version history and release notes.

MIT