Extending
How extends combines the presets with your own tsconfig, and where files, paths, environments and frameworks are set.
@workspace/typescript-config 1.0.0Developmentunreleased, maintained in Foundation as a copy
How extends works here#
"extends": "@workspace/ is resolved like a package import: from
the folder of your tsconfig. upwards to node_, which
pnpm links to your copy in packages/. That is why the package is declared and
installed (see Getting started). The package has no
exports map; the four file names are its whole surface.
TypeScript then reads three layers, each over the previous one:
base.;json the preset you extend;
your own
tsconfig..json
Two rules decide the result:
A setting is replaced as a whole.
compilermerge key by key, but an array such asOptions lib,typesorpluginsis not merged: yours replaces the inherited one. To add a type package tonodejs., restatejson node:JSON{ "extends": "@workspace/typescript-config/nodejs.json", "compilerOptions": { "types": ["node", "vitest/globals"] }, "include": ["src"]}Without
node, the result is"types": ["vitest/only, andglobals"] processis unknown.Paths are relative to the file that sets them.
include,exclude,out,Dir rootandDir pathsin yourtsconfig.are resolved from your folder. The presets set none of them.json
What you add#
| Concern | Where | Example |
|---|---|---|
| which files | include, exclude | "include": ["src"], "exclude": ["node_ |
| output | no, or out and root | "no; or "out |
| import aliases | paths | "paths": {"@/ |
| environment | types | "types": ["node"] for Node globals outside nodejs. |
| test globals | types, with what the preset already had | "types": ["node", "vitest/ |
| framework | the preset, plus the framework's own files | nextjs. with next- in include |
| editor plugins | plugins, restating the preset's | "plugins": [{"name": "next"}] |
These are the additions the shared standard allows (docs/ § 3 in
your copy of the standards): include, exclude, out, root, paths, no, types
and plugins.
Re-declaring lib is possible but almost never needed: the base already carries the shared set,
and a local copy drifts from it.
What you do not change#
Do not relax strict, no, target, module or declaration.
They are the guarantees every package of the Active packages is written against. A repository that
must deviate records that as a decision in its own docs/, with its reason; a
deviation that would serve every repository is proposed to the maintainer of Foundation instead.
Do not edit the copy in packages/. A preset change is made in Foundation, with
a changelog entry, and reaches every repository with the next copy.
Packages that travel to other repositories#
A package that is itself handed to other repositories (such as active- and active-)
does not extend this configuration. A bundler in the receiving repository reads the
tsconfig. of every source file it compiles, and a path to a preset that the receiver may not
have would break that. Such a package carries a self-contained tsconfig. with the values of
the preset at the time it was written. Your own apps and packages extend the presets.