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.
-
Install the package:
Terminal window pnpm add -D typescript @repobuddy/typescript -
Pick the language level.
language/buddytargets ES2020. -
Pick one module file. For bundler output, use
modules/es2022. For a Node.js package, usemodules/buddyormodules/nodenext. -
Add
interop/buddyso single-file transpilers can compile the code. -
Pick a strictness level from type-checking. This example uses
buddy-strictest. -
Add
emit/buddyfor declarations and source maps. -
Add any extras:
language/reactfor JSX with the automatic runtime.modules/ui-assetsto import.cssand other files that have declaration files.javascript/buddyto compile and check.jsfiles.projects/compositefor project references.
-
Set your own
outDir,rootDir, andinclude. 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.
Finished config
Section titled “Finished config”{ "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"]}Verify
Section titled “Verify”- Run
pnpm exec tsc --showConfig. Check that the output lists"module": "es2022","moduleResolution": "bundler","target": "es2020", and"noImplicitOverride": true. - Run
pnpm exec tsc -p .. It exits with code0and writes.js,.d.ts, and.mapfiles todist/.
Related
Section titled “Related”- tsconfig presets
- Known failures: files that need an extra option or an older TypeScript.