liveBook · Manning

Lib configuration property

As explained in Essential TypeScript 5, Third Edition

The lib configuration property selects the library type definitions that the TypeScript compiler includes for a project.

The lib property selects the library type definitions that the TypeScript compiler includes. Without an explicit value, TypeScript derives its default definitions from target. Use lib when the runtime supports features outside that default, such as Map while targeting ES5. section 5.7

Enabling Map while targeting ES5

A project using Map can keep ES5 output while adding the collection definitions in tools/tsconfig.json: { "compilerOptions": { "target": "ES5", "outDir": "./dist", "rootDir": "./src", "noEmitOnError": true, "lib": ["es5", "dom", "es2015.collection"] } } The src/index.ts example creates a Map, stores Bob and Alice with their cities, and prints the entries. Without the collection definition, the compiler reports that it cannot find Map.

lib changes what the compiler may type-check; it does not add missing runtime objects or transform collections for older environments. Confirm that the runtime already provides the selected feature, or provide a polyfill such as core-js. section 5.7

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Explains standard, environment, and per-feature values with a Map configuration, but stops short of polyfill implementation.
Examples
Demonstrates a Map program and an ES5 tsconfig.json using es2015.collection alongside es5 and dom.
What you can do after
Operate/configure TypeScript projects by selecting library definitions and checking that runtime support or a polyfill exists.
How it connects
Connects target, DOM, WebWorker, Map, Set, promises, iterators, and polyfills.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Essential TypeScript 5, Third Edition. The section links point to the parts of the book it draws on.