Presets
The three presets on one base, what each changes, and how to choose by what your type-check reaches.
@workspace/typescript-config 1.0.0Developmentunreleased, maintained in Foundation as a copy
extends | For |
|---|---|
@workspace/ | Node.js code with no browser surface: servers, tooling, scripts |
@workspace/ | code whose type-check reaches . files or DOM types, directly or through a dependency |
@workspace/ | a Next.js application |
base. is the root the three presets extend. Do not extend it yourself.
What each preset changes#
| Setting | base. | nodejs. | react- | nextjs. |
|---|---|---|---|---|
lib | es2022, esnext., DOM, DOM. | es2022, esnext. | from base | from base |
types | not set | ["node"] | not set | not set |
jsx | not set | not set | react- | preserve |
no | not set | true | not set | true |
allow | not set | not set | not set | true |
plugins | not set | not set | not set | [{"name": "next"}] |
What each setting means in practice:
nodejs.has no DOM:json documentorwindowis an error (TS2584: Cannot find name 'document'). It loads the Node types, so it needs@types/.node react-compiles JSX with the automatic runtime: nolibrary. json import Reactper file. It does not setno; run it asEmit tsc --no, or setEmit outwhen the package does emit.Dir nextjs.hands JSX to Next.js unchanged, allowsjson .files, and never emits. Itsjs nextplugin adds Next's checks in the editor;tscon the command line ignores it.
With TypeScript 6, a preset that does not set types loads no global type packages: Node's
process is unknown in a react- package until you add "types": ["node"].
Choosing a preset#
Packages in a workspace are used from source. When your package imports another package, your
type-check reads that package's . and . files under your settings. So the question is
not whether your package contains React, but what its type-check reaches:
| Your package or app | Preset |
|---|---|
| a Next.js application | nextjs. |
reaches a . file or DOM types, in its own files or a dependency's | react- |
| a React application without Next (for example Vite) | react- |
| neither | nodejs. |
A Node package that imports a component library fails under nodejs., although it has no
JSX of its own:
error TS6142: Module 'widgets/greeting' was resolved to '…/widgets/src/greeting.tsx', but '--jsx' is not set.Under react- the same package type-checks. ESLint chooses the other way round, by
your own files only; see eslint-config.
Examples#
A React library that emits nothing:
{ "extends": "@workspace/typescript-config/react-library.json", "include": ["src"], "exclude": ["node_modules", "dist"]}A Next.js application. Next creates next-; include it, with the types Next generates
under .:
{ "extends": "@workspace/typescript-config/nextjs.json", "compilerOptions": { "paths": { "@/*": ["./*"] }, "plugins": [{"name": "next"}] }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "exclude": ["node_modules", ".next"]}The example restates the next plugin because a plugins of your own replaces the inherited
one; see Extending.