Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท tsconfig: Language, Modules and Emit Options

TypeScript lib option

Reference for the lib compiler option: choosing the built-in typings for ECMAScript, DOM and other APIs, how it differs from target, and common errors.

lib selects the built-in declaration files the compiler loads: the types of Array, Promise, Map, Object.groupBy, and, if you ask for it, the browser DOM with document and fetch. It decides what the type checker believes exists. It does not add anything at runtime, so a lib entry must describe what your runtime really provides.

When lib is not set, the compiler picks a default from target; in that default the DOM is included. Setting lib replaces the default completely, so list every group you need.

JSON
{ "compilerOptions": { "lib": ["es2024", "dom", "dom.iterable"] } }

Try it

This site compiles with the newest ECMAScript library and no DOM.

TypeScript Newer built-ins in the types

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript No DOM in this lib setup

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

JSON
{ "compilerOptions": { "lib": ["es2023", "dom"] } }
Group Provides
es5, es2015 ... es2025 The built-in library of that ECMAScript edition (each includes the earlier ones).
esnext The newest built-ins the compiler has.
dom, dom.iterable, dom.asynciterable Browser APIs: document, window, fetch, element types, and iterator support for DOM collections.
webworker Types for web worker scope.
es2021.promise, es2022.array, ... Single features, for a precise setup.
decorators, scripthost Smaller special groups.

Command line: tsc --lib es2024,dom.

Usage notes

  • The compiler error for a missing group suggests the fix: for document it says Cannot find name 'document'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'.
  • A Node-only project usually has no use for dom. Leaving it out stops accidental use of window and document, and avoids clashes between DOM and Node types (setTimeout returning number versus Timeout).
  • Node's own APIs (fs, process) are not part of lib. They come from @types/node, controlled with types.
  • Matching the runtime is your job: lib: ["es2024"] does not polyfill Object.groupBy on a browser that lacks it.
  • Using target without lib is fine for simple projects. Add lib when you need the DOM, or a newer API than the target implies.
  • Typos in group names produce an error listing the allowed values.