TypeScript Compiler Options
lib — TypeScript compiler option
Selects built-in declaration libraries exposed to the type checker. Explicit lists replace the default library selection; DOM supplies browser declarations, not a browser runtime. Adding ES2015 or later allows Map typing without installing a Map implementation. Select libraries to match the actual host, not just the desired syntax target. Default: Target-dependent default libraries when omitted. Create the named files in a clean local project and run tsc -p tsconfig.json. Expected emitted files: dist/example.js. Run node dist/example.js; expected stdout: '4'. Tested with TypeScript 5.8.3 and Node.js 22.16.0; local project example, not a single-file editor.
Formal Syntax & Structure
typescript syntaxtypescript
{ "compilerOptions": { "lib": [ "ES2022", "DOM" ] }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| lib | array of library names | Set in compilerOptions; Target-dependent default libraries when omitted. |
Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "noEmitOnError": true, "outDir": "dist", "lib": [ "ES2022", "DOM" ] }, "files": [ "example.ts" ]}// File: example.tsconst counts = new Map<string, number>([["ready", 4]]);console.log(counts.get("ready"));