The ECMAScript Standard Libraries provide type definitions for JavaScript's built-in objects, methods, and APIs. These declaration files (.d.ts) define the types for core language features like Object, Array, Map, and Promise, enabling TypeScript to perform type checking on standard JavaScript APIs. The libraries are organized by ECMAScript version (ES5, ES2015, ES2020, etc.) and collectively form the foundational type system that all TypeScript code builds upon.
For information about DOM and Web Worker API type definitions, see DOM and Web Worker APIs. For general information about standard library type definitions, see Standard Library Type Definitions.
The standard library type definitions are distributed across multiple declaration files in src/lib/, each corresponding to a specific ECMAScript version or feature set. The compiler includes the appropriate libraries based on the target and lib compiler options.
Title: Library Dependency Structure
Sources: src/lib/es5.d.ts1-7 src/lib/es2015.iterable.d.ts1 src/lib/es2020.bigint.d.ts1 src/lib/esnext.intl.d.ts1
The src/lib/es5.d.ts file defines the foundational JavaScript types that existed in ECMAScript 5. This library is always included regardless of the target setting.
| Function/Value | Type Signature | Description |
|---|---|---|
eval | (x: string): any | Evaluates JavaScript code |
parseInt | (string: string, radix?: number): number | Parses integers |
parseFloat | (string: string): number | Parses floating-point numbers |
isNaN | (number: number): boolean | Checks for NaN |
isFinite | (number: number): boolean | Checks if finite |
NaN | number | Not-a-Number constant |
Infinity | number | Infinity constant |
Sources: src/lib/es5.d.ts8-42
Title: ObjectConstructor API Mapping
The ObjectConstructor interface defines static methods on the Object constructor:
| Method | Signature | Line Reference |
|---|---|---|
getPrototypeOf | (o: any): any | src/lib/es5.d.ts149 |
getOwnPropertyDescriptor | (o: any, p: PropertyKey): PropertyDescriptor | undefined | src/lib/es5.d.ts157 |
getOwnPropertyNames | (o: any): string[] | src/lib/es5.d.ts164 |
create | (o: object | null, properties?: PropertyDescriptorMap): any | src/lib/es5.d.ts170-177 |
defineProperty | <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor): T | src/lib/es5.d.ts185 |
Sources: src/lib/es5.d.ts137-192
The src/lib/es2015.core.d.ts file augments existing ES5 interfaces with new methods introduced in ES2015.
New instance methods for searching and modification:
find<S>(predicate: (value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined src/lib/es2015.core.d.ts11findIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number src/lib/es2015.core.d.ts23fill(value: T, start?: number, end?: number): this src/lib/es2015.core.d.ts33copyWithin(target: number, start: number, end?: number): this src/lib/es2015.core.d.ts44Sources: src/lib/es2015.core.d.ts1-47
ES2015 adds specialized mathematical functions:
clz32(x: number): number: Leading zero bits src/lib/es2015.core.d.ts87imul(x: number, y: number): number: 32-bit multiplication src/lib/es2015.core.d.ts94sign(x: number): number: Sign of x src/lib/es2015.core.d.ts100hypot(...values: number[]): number: Square root of sum of squares src/lib/es2015.core.d.ts173Sources: src/lib/es2015.core.d.ts82-180
The src/lib/es2015.collection.d.ts file defines Map, Set, WeakMap, and WeakSet.
| Interface | Key Methods | Description |
|---|---|---|
Map<K, V> | get, set, has, delete, clear | Key-value pairs src/lib/es2015.collection.d.ts1-31 |
Set<T> | add, has, delete, clear | Unique values src/lib/es2015.collection.d.ts74-100 |
WeakMap<K, V> | get, set, has, delete | Keys must be WeakKey src/lib/es2015.collection.d.ts47-66 |
Sources: src/lib/es2015.collection.d.ts1-143
The src/lib/es2015.iterable.d.ts defines how objects describe their iteration behavior.
Title: Iteration Protocol Entities
IteratorResult<T, TReturn>: A union of IteratorYieldResult and IteratorReturnResult src/lib/es2015.iterable.d.ts21Iterator<T, TReturn, TNext>: Defines the next, return, and throw methods src/lib/es2015.iterable.d.ts23-28Sources: src/lib/es2015.iterable.d.ts11-32
The Promise API is defined across es2015.promise.d.ts and augmented by es2015.iterable.d.ts.
PromiseConstructor.all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]> src/lib/es2015.iterable.d.ts237PromiseConstructor.resolve<T>(value: T | PromiseLike<T>): Promise<Awaited<T>> src/lib/es2015.promise.d.ts60Sources: src/lib/es2015.promise.d.ts1-63 src/lib/es2015.iterable.d.ts228-245
Introduced in ES2020, BigInt allows representing integers larger than $2^{53}-1$.
BigIntConstructor: Includes asIntN and asUintN for bit-clamping src/lib/es2020.bigint.d.ts105-123BigInt64Array: A typed array for 64-bit signed integers src/lib/es2020.bigint.d.ts131Sources: src/lib/es2020.bigint.d.ts89-131
The Intl namespace provides locale-sensitive string comparison, number formatting, and date/time formatting.
RelativeTimeFormat: Formats time differences (e.g., "in 3 days") src/lib/es2020.intl.d.ts128-166DateTimeFormat: Augmented in esnext.intl.d.ts to support Temporal objects like PlainDate and Instant src/lib/esnext.intl.d.ts4-11Sources: src/lib/es2020.intl.d.ts2-166 src/lib/esnext.intl.d.ts3-91
The compiler's test harness utilizes these libraries via a virtual file system.
builtFolder: The location where built libraries are stored (/.ts) src/harness/vfsUtil.ts10FileSystem: The class managing the virtual file system during execution of compiler tests src/harness/vfsUtil.ts55Sources: src/harness/vfsUtil.ts7-55
Refresh this wiki