Skip to content

Compose your own tsconfig

When tsconfig/monorepo does not fit, pick one file per category and list them in an extends array. This guide builds a config for a library that a bundler consumes.

extends arrays need TypeScript 5.0 or later.

  1. Install the package:

    Terminal window
    pnpm add -D typescript @repobuddy/typescript
  2. Pick the language level. language/buddy targets ES2020.

  3. Pick one module file. For bundler output, use modules/es2022. For a Node.js package, use modules/buddy or modules/nodenext.

  4. Add interop/buddy so single-file transpilers can compile the code.

  5. Pick a strictness level from type-checking. This example uses buddy-strictest.

  6. Add emit/buddy for declarations and source maps.

  7. Add any extras:

  8. Set your own outDir, rootDir, and include. No building block sets them.

Order matters. When two files set the same option, the later file in the array wins, and your own compilerOptions win over all of them.

{
"extends": [
"@repobuddy/typescript/tsconfig/language/buddy",
"@repobuddy/typescript/tsconfig/modules/es2022",
"@repobuddy/typescript/tsconfig/interop/buddy",
"@repobuddy/typescript/tsconfig/type-checking/buddy-strictest",
"@repobuddy/typescript/tsconfig/emit/buddy"
],
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src"]
}
  1. Run pnpm exec tsc --showConfig. Check that the output lists "module": "es2022", "moduleResolution": "bundler", "target": "es2020", and "noImplicitOverride": true.
  2. Run pnpm exec tsc -p .. It exits with code 0 and writes .js, .d.ts, and .map files to dist/.