Active Foundation

Search documentation

Search all pages, headings and text, in the current package or topic or in all documentation.

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

extendsFor
@workspace/typescript-config/nodejs.jsonNode.js code with no browser surface: servers, tooling, scripts
@workspace/typescript-config/react-library.jsoncode whose type-check reaches .tsx files or DOM types, directly or through a dependency
@workspace/typescript-config/nextjs.jsona Next.js application

base.json is the root the three presets extend. Do not extend it yourself.

What each preset changes#

Settingbase.jsonnodejs.jsonreact-library.jsonnextjs.json
libes2022, esnext.temporal, DOM, DOM.Iterablees2022, esnext.temporalfrom basefrom base
typesnot set["node"]not setnot set
jsxnot setnot setreact-jsxpreserve
noEmitnot settruenot settrue
allowJsnot setnot setnot settrue
pluginsnot setnot setnot set[{"name": "next"}]

What each setting means in practice:

  • nodejs.json has no DOM: document or window is an error (TS2584: Cannot find name 'document'). It loads the Node types, so it needs @types/node.

  • react-library.json compiles JSX with the automatic runtime: no import React per file. It does not set noEmit; run it as tsc --noEmit, or set outDir when the package does emit.

  • nextjs.json hands JSX to Next.js unchanged, allows .js files, and never emits. Its next plugin adds Next's checks in the editor; tsc on 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-library.json 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 .ts and .tsx files under your settings. So the question is not whether your package contains React, but what its type-check reaches:

Your package or appPreset
a Next.js applicationnextjs.json
reaches a .tsx file or DOM types, in its own files or a dependency'sreact-library.json
a React application without Next (for example Vite)react-library.json
neithernodejs.json

A Node package that imports a component library fails under nodejs.json, although it has no JSX of its own:

Text
error TS6142: Module 'widgets/greeting' was resolved to '…/widgets/src/greeting.tsx', but '--jsx' is not set.

Under react-library.json 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:

JSON
{  "extends": "@workspace/typescript-config/react-library.json",  "include": ["src"],  "exclude": ["node_modules", "dist"]}

A Next.js application. Next creates next-env.d.ts; include it, with the types Next generates under .next/types:

JSON
{  "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.

This page as Markdown