API reference
TypeScript API reference
advanced TypeScript for large codebases
- Identifiers
- 110
- With full guides
- 105
- Types
- 6
Topics covered
- Generics
- Discriminated unions
- Conditional types
- Mapped types
- Template literal types
- The satisfies operator
- Type narrowing
- Utility types
Function
| Name | What it does |
|---|---|
Mapped Types | Mapped types transform an existing type by iterating over a union of property keys, commonly keyof another type. They can change property values, modifiers, and—using key remapping—property names. |
Conditional Types | Conditional types choose one of two types by testing whether one type is assignable to another. They can map generic inputs to precise outputs, distribute over unions, and infer types from matched structures. |
Template Literal Types | Template literal types build string-literal types from fixed text and interpolated types. Unions in placeholders expand into every permitted combination, enabling type-safe naming patterns and inferred string structure. |
Index Signatures | Index signatures describe values for properties whose names are not known ahead of time. They support dictionary-like objects while enforcing the declared value type for compatible keys and named properties. |
Discriminated Unions | A discriminated union is a union of object variants sharing a literal-typed tag, such as kind or state. TypeScript uses checks of that tag to narrow a value to the matching variant. |
Tuple Types | Tuple types describe fixed-position arrays: each index can have a different type, and the tuple can also express optional or rest elements. Labels improve readability, while readonly prevents mutation. |
Generics | Generics parameterize functions, classes, interfaces, and types so one declaration can work with many concrete types while preserving relationships between them. Type arguments may be written explicitly or inferred from usage. |
Type Guards | Type guards are runtime checks that TypeScript uses to narrow a value to a more specific type along control-flow paths. Use built-in JavaScript checks or a user-defined predicate for custom object validation. |
Type Predicates | Type predicates let custom boolean functions tell TypeScript how to narrow a value. A return type like value is Widget makes a successful call refine the argument to Widget. |
Declaration Merging | Declaration merging combines compatible same-named TypeScript declarations into one definition. It supports patterns such as interface extension by repeated declarations, namespace combination, and module augmentation. |
Module Augmentation | Module augmentation lets a module add type declarations to an existing module's named exports. The declarations merge with the original API, while any runtime patch must be implemented and loaded separately. |
Const Type Parameters | A const type parameter makes const-like inference the default for eligible inline object, array, and primitive expressions. It helps generic APIs preserve literal properties and tuple types without requiring callers to write as const. |
Variadic Tuple Types | Variadic tuple types let generic spreads capture and rebuild tuple or array sequences. They support tuple concatenation, fixed elements around variable segments, and strongly typed function composition. |
assertion functions | Assertion functions combine runtime validation with compile-time narrowing. If the function returns successfully, TypeScript treats an asserted condition or type predicate as established in the rest of the relevant control-flow scope. |
Interface
| Name | What it does |
|---|---|
Iterable | Iterable<T> describes values that implement Symbol.iterator and yield elements of type T. It lets functions accept arrays and other iterable collections through one generic type. |
Iterator | Iterator describes a stateful producer whose next method yields values until completion. Its generic parameters separately model yielded values, the final return value, and inputs passed to next. |
IterableIterator | IterableIterator represents an object that is both iterable and an iterator. It can participate in for-of and similar iteration constructs while producing values through the iterator protocol. |
AsyncIterable | AsyncIterable represents a value that supports asynchronous iteration through Symbol.asyncIterator. Its iterator produces promise-based iteration results for use with for await...of. |
PromiseLike | |
ArrayLike | |
PropertyDescriptor | PropertyDescriptor is the descriptor parameter used in TypeScript's documented method-decorator example. It represents runtime metadata for the decorated member and is passed after the target and property key. |
Generator | Generator<T, TReturn, TNext> describes a generator as a typed iterator that is also iterable. Its parameters separately model yielded values, the final return value, and values passed to next. |
AsyncGenerator | AsyncGenerator is the iterator type produced by an async generator function. It yields values asynchronously and exposes promise-based iteration operations. |
TypedPropertyDescriptor |
Type Alias
| Name | What it does |
|---|---|
Partial | Partial<Type> constructs a type with every property of Type made optional. It represents any subset of the original type and is commonly used for partial updates. |
Required | Required<Type> transforms an object type so all of its properties are required. It is the inverse counterpart to Partial<Type>. |
Pick | Pick<Type, Keys> creates a type containing only the properties named by Keys from Type. It is available globally and supports a single property name or a union of property names. |
Omit | Omit<Type, Keys> creates a new type with all properties from Type except the keys listed in Keys. It is globally available and complements Pick. |
Record | Record<Keys, Type> constructs an object type whose keys come from Keys and whose values all use Type. It is useful for strongly typed dictionaries and lookup tables. |
Readonly | Readonly<Type> creates a type whose properties cannot be reassigned by TypeScript. It is useful for describing frozen or otherwise read-only object views. |
ReturnType | ReturnType<Type> extracts the return type of a function type into a reusable type. It is globally available and was introduced in TypeScript 2.8. |
Parameters | Parameters<Type> creates a tuple containing the parameter types of a function type. It is useful for reusing or transforming a function's argument list without manually duplicating it. |
Awaited | Awaited<Type> models the result of await and Promise.then by recursively unwrapping promises. It also distributes over unions, preserving non-promise members. |
Exclude | Exclude<UnionType, ExcludedMembers> creates a type by removing from a union every member assignable to the excluded type. It is globally available and useful for deriving narrower unions. |
Extract | Extract filters a union by retaining the members of Type that are assignable to Union. It is a globally available built-in utility type for selecting compatible variants or types. |
NonNullable | NonNullable<Type> removes null and undefined from a type. It is useful for describing values that remain after nullish cases have been ruled out. |
InstanceType | InstanceType<Type> derives the instance type produced by a constructor function. For a class, pass typeof ClassName to obtain the type of objects created with new ClassName(). |
ConstructorParameters | ConstructorParameters<Type> extracts the parameter types of a constructor as a tuple or array. It is useful for reusing and checking constructor arguments without duplicating their declarations. |
Uppercase | Uppercase<StringType> converts every character in a string type to its uppercase form. It is an intrinsic compiler type commonly used with template literal types to derive uppercase string formats. |
Lowercase | Lowercase<StringType> converts every character in a string type to its lowercase equivalent. Use it to derive normalized string-literal types, including names built with template literal types. |
Capitalize | Capitalize<StringType> converts the first character of a string-literal type to uppercase. It is an intrinsic compiler type commonly used with template literal and mapped types to generate names. |
Uncapitalize | Uncapitalize is a built-in intrinsic type that converts the first character of a string type to lowercase. The rest of the string remains unchanged. |
NoInfer | NoInfer<Type> blocks inference from the wrapped type while remaining identical to Type for other purposes. Use it when one generic argument should establish a type and another should only be checked against it. |
ThisType | ThisType<T> is a marker for the contextual type of this inside object-literal methods. It is commonly used in factory descriptors so methods can access combined data and method members. |
OmitThisParameter | OmitThisParameter<Type> removes an explicit this parameter from a function type. Functions without an explicit this remain unchanged, while generic information and all but the final overload are not preserved. |
ThisParameterType | ThisParameterType<Type> extracts a function's explicit this-parameter type. It returns unknown when the function type has no this parameter. |
any | any opts a value out of TypeScript’s static checking, allowing broad assignments and unchecked property access. It helps bridge untyped JavaScript or dependencies, but sacrifices type safety and should be tightly contained. |
void | void describes functions whose return value is not used. It is inferred for functions without a returned value and has special behavior when used as a callback return type. |
object | A type alias names a TypeScript type, commonly an object shape with typed properties. It improves reuse and readability without creating a distinct runtime or nominal type. |
string | A type alias gives a reusable name to a type expression. Unlike a class or runtime value, it is erased during compilation and does not create a distinct type identity. |
number | A number type alias assigns a domain-specific name to TypeScript’s existing number type. It improves readability but does not create a distinct or nominal numeric type. |
boolean | The primitive boolean type represents the two values true and false. In TypeScript, boolean is equivalent to the union true | false; use lowercase boolean rather than boxed Boolean. |
bigint | bigint is TypeScript’s primitive type for arbitrarily large integers. Values come from BigInt() or integer literals with an n suffix, and bigint arithmetic cannot mix with number operands. |
symbol | symbol is a primitive type for immutable, unique values created with Symbol(). It can be used for object-property keys, while unique symbol preserves the identity of a specific symbol. |
Const
| Name | What it does |
|---|---|
unknown | unknown is TypeScript’s safe top type for values whose runtime type is not yet known. It accepts values of any type, but requires narrowing or an assertion before most use. |
never | never represents impossible values and unreachable execution paths. It is especially useful for exhaustive checking of narrowed unions and for functions that throw or never terminate. |
asserts | asserts defines assertion signatures that narrow types after a function returns successfully. It supports asserting a condition or declaring that a parameter has a specific type. |
abstract | TypeScript’s abstract modifier defines base classes and members that require subclass implementations. Abstract classes cannot be instantiated directly, but they can combine shared implementations with enforced subclass contracts. |
keyof | keyof T creates a type containing the permitted keys of T. Explicit properties produce literal-key unions, while index signatures can produce string, number, or both. |
typeof | In a type context, TypeScript’s typeof operator obtains the static type of a variable or property. It is especially useful for deriving reusable types from values and composing with utilities such as ReturnType. |
infer | infer captures a type component while a conditional type checks a pattern. The captured variable is usable in the true branch, enabling reusable type-level extraction patterns. |
extends | extends constrains generic type parameters and forms the assignability test in conditional types. In conditional types, it selects one of two branches and can distribute over unions. |
as | The as operator is a compile-time type assertion that tells TypeScript to treat an expression as a chosen type. It performs no runtime conversion or validation. |
satisfies | The satisfies operator checks that an expression conforms to a target type without changing the expression’s inferred type. It catches structural mistakes while preserving precise property and method inference. |
is | The is keyword forms a type predicate in a function return type. It connects a runtime check to control-flow narrowing, letting TypeScript treat a compatible parameter as a specific type when the function returns true. |
readonly | The readonly property modifier lets an object property be assigned during initialization but prevents later assignments through that property. It is a compile-time, shallow protection rather than runtime deep immutability. |
declare | The declare keyword describes a runtime-provided symbol to TypeScript without implementing it in the current source. It is commonly used in .d.ts files and for external variables, functions, classes, namespaces, and modules. |
namespace | |
module | A TypeScript file with a top-level import or export is a module; a file without either is a script. Modules have their own scope, while scripts contribute declarations to the global scope. |
type | TypeScript type operators derive new types from existing types or values. The page introduces generics, keyof, typeof, indexed access, conditional, mapped, and template literal types as tools for concise, maintainable type transformations. |
interface | An interface names an object type and describes its required or optional members. TypeScript checks interface compatibility structurally, and interfaces can be extended or reopened. |
enum | Enums define named constants and a type for a finite set of cases. TypeScript supports numeric, string, regular, and const enums, with regular enums available at runtime and const-enum members inlined during compilation. |
const | TypeScript’s const creates a block-scoped binding that must be initialized and cannot be reassigned. The referenced object or array may still be mutable unless additional type-level or runtime measures are used. |
unique | unique symbol gives each symbol a declaration-specific identity. It is useful for strongly typed tokens and symbol-keyed APIs where distinct symbols must remain incompatible. |
override | override marks a derived-class member as an intentional replacement for an inherited member. TypeScript verifies that the base class contains a matching member, while noImplicitOverride can require the annotation across a codebase. |
accessor | TypeScript accessors use get and set methods to control property reads and writes while preserving property-like syntax. A getter-only accessor is inferred as readonly. |
using | The using declaration creates a fixed binding like const and automatically calls the resource's Symbol.dispose method when its scope ends. Cleanup also occurs on early exits and follows last-in-first-out order. |
in | TypeScript recognizes JavaScript’s in property check as a type guard. It narrows union members based on whether the tested key is required, optional, or unlisted. |
out | |
strict | The strict compiler option enables TypeScript’s strict mode family, giving stronger guarantees of program correctness. Individual strict-family checks can be disabled when needed. |
noImplicitAny | noImplicitAny makes TypeScript report errors when it would infer any because a value lacks an annotation or usable contextual type. Enable it in compilerOptions to prevent accidental loss of type checking. |
strictNullChecks | strictNullChecks controls whether null and undefined are treated as distinct types. When enabled, TypeScript requires code to handle possibly absent values before using them as definite values. |
strictFunctionTypes | strictFunctionTypes makes function parameter comparisons contravariant instead of bivariant, catching unsafe callback assignments. It is enabled by strict mode but does not apply to methods or constructors. |
esModuleInterop | Enables more accurate interoperability between ES-style imports and CommonJS, AMD, or UMD modules. It changes checking and emitted helpers so default imports work as expected and namespace imports remain valid module objects. |
target | The target compiler option selects the ECMAScript version for emitted JavaScript and compatible library declarations. Choose the lowest runtime level your supported environments can execute. |
moduleResolution | moduleResolution chooses how TypeScript maps import, export, and require specifiers to files. Configure it to match the target runtime or bundler, such as nodenext for modern Node.js or bundler for bundler-managed projects. |
jsx | The jsx compiler option controls how JSX in .tsx files is emitted. TypeScript supports preserving JSX, classic React output, automatic production/development runtimes, and React Native-style preservation. |
paths | The paths compiler option maps import names or prefixes to lookup locations for TypeScript module resolution. It helps the compiler understand aliases, but does not rewrite emitted imports or configure runtime resolution. |
baseUrl | Sets the directory TypeScript uses to resolve bare module specifiers. It can make imports such as "utils/date" resolve from a configured project directory before node_modules. |
lib | The lib compiler option selects the JavaScript and environment API declarations available during type checking. Use it to align TypeScript's known APIs with the actual runtime, browser platform, and polyfills in a project. |
allowJs | allowJs lets a TypeScript project include and import JavaScript files, enabling mixed JS/TS codebases. It is useful for incremental migration and can support generating declaration files from JavaScript. |
declaration | The declaration compiler option generates .d.ts files that describe a project’s external API. Consumers and editor tools can use them for type checking and IntelliSense without inspecting implementation code. |
sourceMap | sourceMap enables source-map generation for emitted JavaScript. Debuggers can use the generated .js.map files to show the original TypeScript source while the JavaScript runs. |
incremental | Enables TypeScript to persist project-graph information between compilations. Later builds can reuse that information to reduce type-checking and emit work. |
composite | composite makes a TypeScript project suitable for project references and build-mode analysis by enforcing a complete, known input set. It also changes the default rootDir and enables declaration output by default. |
skipLibCheck | skipLibCheck skips full type checking of declaration files to reduce compilation time. It can improve build speed but may hide type inconsistencies, so dependency-resolution fixes are preferable when duplicate library types are the cause. |
isolatedModules | isolatedModules makes TypeScript report code that cannot be safely transpiled one file at a time. It is designed for pipelines using single-file transformers such as Babel or transpileModule. |
verbatimModuleSyntax | verbatimModuleSyntax makes module emit follow the import/export syntax you write: unmarked declarations remain, while type-marked declarations are erased. It also prevents ECMAScript module syntax from being rewritten into CommonJS. |
noUncheckedIndexedAccess | The noUncheckedIndexedAccess compiler option adds undefined to undeclared indexed properties and array element reads. This makes missing keys and out-of-bounds access visible to the type checker. |
exactOptionalPropertyTypes | exactOptionalPropertyTypes makes optional property declarations exact: omission remains allowed, but undefined is not automatically added to the property's assignable values. Explicitly include undefined when that value should be permitted. |
Decorator
| Name | What it does |
|---|---|
ClassDecorator | A class decorator is a function applied to a class declaration at runtime. It receives the class constructor and can observe, modify, or replace the class by returning another constructor. |
MethodDecorator | A legacy method decorator is placed before a method and receives its target, name, and property descriptor at runtime. It can observe, modify, or replace the method definition. |
PropertyDecorator | A legacy property decorator is a runtime callback attached immediately before a class property. It receives the class constructor or prototype and the property name, so it can observe the declaration but cannot directly modify its descriptor. |
ParameterDecorator | A parameter decorator is a runtime callback placed before a parameter in a class constructor or method. It receives the owning target, member name, and parameter index, and is primarily used to observe or record parameter metadata. |
AccessorDecorator | An accessor decorator runs on a getter or setter’s property descriptor, letting code observe, modify, or replace the accessor definition. It receives the owning constructor or prototype, the member name, and the descriptor. |
Command
| Name | What it does |
|---|---|
tsc | tsc is the TypeScript compiler command. Run it with no inputs to build the nearest configured project, or provide files and compiler options for a direct compilation. |
tsc --init | Initializes a TypeScript project by generating a tsconfig.json in the current directory. The current template is concise and supplies modern compiler defaults. |
tsc --watch | tsc --watch keeps the TypeScript compiler running and monitors input files for changes. Configure its file and directory-watching behavior with watch-related compiler options or watchOptions in tsconfig.json. |
tsc --build | tsc --build (or tsc -b) orchestrates TypeScript projects connected by project references. It discovers dependencies, checks freshness, and builds stale projects in dependency order. |
tsc --noEmit | tsc --noEmit type-checks a TypeScript program without generating JavaScript, source maps, or declaration files. It is commonly used when another tool performs transpilation or bundling. |
Search across every package and filter by type in your dashboard.
Start learning