Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

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

NameWhat it does
Mapped TypesMapped 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 TypesConditional 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 TypesTemplate 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 SignaturesIndex 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 UnionsA 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 TypesTuple 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.
GenericsGenerics 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 GuardsType 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 PredicatesType 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 MergingDeclaration 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 AugmentationModule 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 ParametersA 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 TypesVariadic 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 functionsAssertion 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

NameWhat it does
IterableIterable<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.
IteratorIterator 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.
IterableIteratorIterableIterator 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.
AsyncIterableAsyncIterable represents a value that supports asynchronous iteration through Symbol.asyncIterator. Its iterator produces promise-based iteration results for use with for await...of.
PromiseLikeInterface
ArrayLikeInterface
PropertyDescriptorPropertyDescriptor 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.
GeneratorGenerator<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.
AsyncGeneratorAsyncGenerator is the iterator type produced by an async generator function. It yields values asynchronously and exposes promise-based iteration operations.
TypedPropertyDescriptorInterface

Type Alias

NameWhat it does
PartialPartial<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.
RequiredRequired<Type> transforms an object type so all of its properties are required. It is the inverse counterpart to Partial<Type>.
PickPick<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.
OmitOmit<Type, Keys> creates a new type with all properties from Type except the keys listed in Keys. It is globally available and complements Pick.
RecordRecord<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.
ReadonlyReadonly<Type> creates a type whose properties cannot be reassigned by TypeScript. It is useful for describing frozen or otherwise read-only object views.
ReturnTypeReturnType<Type> extracts the return type of a function type into a reusable type. It is globally available and was introduced in TypeScript 2.8.
ParametersParameters<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.
AwaitedAwaited<Type> models the result of await and Promise.then by recursively unwrapping promises. It also distributes over unions, preserving non-promise members.
ExcludeExclude<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.
ExtractExtract 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.
NonNullableNonNullable<Type> removes null and undefined from a type. It is useful for describing values that remain after nullish cases have been ruled out.
InstanceTypeInstanceType<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().
ConstructorParametersConstructorParameters<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.
UppercaseUppercase<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.
LowercaseLowercase<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.
CapitalizeCapitalize<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.
UncapitalizeUncapitalize is a built-in intrinsic type that converts the first character of a string type to lowercase. The rest of the string remains unchanged.
NoInferNoInfer<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.
ThisTypeThisType<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.
OmitThisParameterOmitThisParameter<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.
ThisParameterTypeThisParameterType<Type> extracts a function's explicit this-parameter type. It returns unknown when the function type has no this parameter.
anyany 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.
voidvoid 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.
objectA 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.
stringA 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.
numberA 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.
booleanThe 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.
bigintbigint 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.
symbolsymbol 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

NameWhat it does
unknownunknown 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.
nevernever 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.
assertsasserts 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.
abstractTypeScript’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.
keyofkeyof 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.
typeofIn 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.
inferinfer 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.
extendsextends 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.
asThe 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.
satisfiesThe 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.
isThe 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.
readonlyThe 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.
declareThe 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.
namespaceConst
moduleA 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.
typeTypeScript 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.
interfaceAn interface names an object type and describes its required or optional members. TypeScript checks interface compatibility structurally, and interfaces can be extended or reopened.
enumEnums 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.
constTypeScript’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.
uniqueunique 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.
overrideoverride 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.
accessorTypeScript 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.
usingThe 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.
inTypeScript 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.
outConst
strictThe strict compiler option enables TypeScript’s strict mode family, giving stronger guarantees of program correctness. Individual strict-family checks can be disabled when needed.
noImplicitAnynoImplicitAny 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.
strictNullChecksstrictNullChecks 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.
strictFunctionTypesstrictFunctionTypes 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.
esModuleInteropEnables 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.
targetThe target compiler option selects the ECMAScript version for emitted JavaScript and compatible library declarations. Choose the lowest runtime level your supported environments can execute.
moduleResolutionmoduleResolution 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.
jsxThe 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.
pathsThe 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.
baseUrlSets 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.
libThe 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.
allowJsallowJs 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.
declarationThe 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.
sourceMapsourceMap 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.
incrementalEnables TypeScript to persist project-graph information between compilations. Later builds can reuse that information to reduce type-checking and emit work.
compositecomposite 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.
skipLibCheckskipLibCheck 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.
isolatedModulesisolatedModules 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.
verbatimModuleSyntaxverbatimModuleSyntax 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.
noUncheckedIndexedAccessThe 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.
exactOptionalPropertyTypesexactOptionalPropertyTypes 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

NameWhat it does
ClassDecoratorA 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.
MethodDecoratorA 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.
PropertyDecoratorA 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.
ParameterDecoratorA 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.
AccessorDecoratorAn 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

NameWhat it does
tsctsc 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 --initInitializes a TypeScript project by generating a tsconfig.json in the current directory. The current template is concise and supplies modern compiler defaults.
tsc --watchtsc --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 --buildtsc --build (or tsc -b) orchestrates TypeScript projects connected by project references. It discovers dependencies, checks freshness, and builds stale projects in dependency order.
tsc --noEmittsc --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