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.
{ "compilerOptions": { "lib": ["es2024", "dom", "dom.iterable"] } }
Try it
This site compiles with the newest ECMAScript library and no DOM.
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.
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
{ "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
documentit saysCannot 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 ofwindowanddocument, and avoids clashes between DOM and Node types (setTimeoutreturningnumberversusTimeout). - Node's own APIs (
fs,process) are not part oflib. They come from@types/node, controlled withtypes. - Matching the runtime is your job:
lib: ["es2024"]does not polyfillObject.groupByon a browser that lacks it. - Using
targetwithoutlibis fine for simple projects. Addlibwhen you need the DOM, or a newer API than the target implies. - Typos in group names produce an error listing the allowed values.