TypeScript Reference

This section documents the current TypeScript release line as published at the official TypeScript documentation, which is the reference these pages are written and verified against. No specific patch version is pinned.

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production, since TypeScript iterates quickly.

This section’s bibliography lists the reference material consulted while preparing these pages.

Welcome to the TypeScript reference. TypeScript is a statically-typed superset of JavaScript: every valid JavaScript program is a valid TypeScript program, and on top of it TypeScript layers a structural type system that is checked at compile time and then erased — the emitted JavaScript carries no types and no runtime cost. That type layer gives you inference, control-flow narrowing, generics, and a small type-level programming language of its own, plus the editor tooling (completion, refactoring, go-to-definition) that the same language service powers. This section documents the current TypeScript release line, framework-agnostic, written and verified against the official TypeScript documentation.

If you are new to TypeScript, read Getting Started with TypeScript first, then The Type System and Everyday Types, followed by Unions and Narrowing — narrowing is where TypeScript stops feeling like annotations and starts feeling like a type system. If you are migrating an existing JavaScript codebase, start instead with JavaScript Interop and Migration and the worked example.

For TypeScript inside a specific framework, see the existing TypeScript with React and TypeScript Essentials for Angular pages, which this section links to rather than duplicates.

What’s covered

Getting started

  • Getting Started with TypeScript — TypeScript as an erasable typed superset, installing and compiling with tsc, the type-stripping runners that run but do not check, the Playground and editor experience, what TypeScript is not, and the compile pipeline end to end.

Core type system

  • The Type System — structural ("duck") typing vs. nominal typing, excess-property checking, types as sets of values, type space vs. value space, and when to infer, annotate, or assert.

  • Everyday Types — the primitives and why to avoid their object wrappers, arrays and readonly arrays, object type literals with optional and readonly members, any / unknown / void / never, and literal types with as const.

  • Unions and Narrowing — union types and their common members, strictNullChecks, every narrowing guard (typeof, truthiness, equality, in, instanceof, assignment), control-flow analysis, discriminated unions with exhaustiveness checking, and type predicates and assertion functions.

  • Objects and Interfaces — interface vs. type and how to choose, property modifiers and index signatures (and their better alternatives), excess-property checking, call and construct signatures, and declaration merging.

Functions, arrays and classes

  • Functions — parameter and return annotations, optional / default / rest parameters, void and never returns, this parameters, call and construct signatures, overloads and when to prefer a union or generic instead, and contextual typing.

  • Arrays and Tuples — T[] vs. Array<T>, readonly arrays, the unsound index-access caveat and noUncheckedIndexedAccess, tuples with optional, rest and labelled elements, and variadic tuple types.

  • Classes — typed fields and accessors, initialization checking, compile-time visibility vs. real #private, static and abstract members, parameter properties, implements vs. extends, override, polymorphic this, and mixins.

Generics and type-level programming

  • Generics — generic functions, interfaces, classes and type aliases, constraints and defaults, inference and how to guide it, const type parameters and NoInfer<T>, and the golden rule for when a type parameter earns its place.

  • Type Manipulation — keyof, the typeof type query, indexed access, conditional types and infer, distributivity, mapped types with key remapping, template literal types, and how to test your types.

  • Utility Types — the built-in Partial / Required / Readonly / Pick / Omit / Record, the union algebra of Exclude / Extract / NonNullable, the function and class reflection types, Awaited, and how each one is implemented.

  • Type Assertions and Modifiers — as and its limits, non-null and definite-assignment assertions, const assertions, the satisfies operator, and any vs. unknown vs. never as the top and bottom types.

  • Enums and Literal Alternatives — numeric, string and const enums, the non-erasable caveat, and the string-literal-union plus as const object alternative.

Modules, declarations and JavaScript interop

  • Modules — ES module syntax and dynamic import, import type and verbatimModuleSyntax, the moduleResolution values, paths mapping, CommonJS/ESM interop, ambient module declarations, and why to prefer modules over namespaces.

  • Declaration Files — what a .d.ts is, declare and ambient declarations, consuming bundled types vs. @types/* from DefinitelyTyped, module and global augmentation, and publishing types with your package.

  • JavaScript Interop and Migration — allowJs and checkJs, the // @ts-check family of comment directives, JSDoc as a type syntax, the migration ladder from plain JavaScript to full strict, and preferring ECMAScript features over TypeScript-only ones.

Configuration and build

  • tsconfig.json and Compiler Options — tsc --init, files / include / exclude, shared config bases, the strict family and the linting-adjacent flags, the emit options, and the diagnostic flags.

  • Project References and Build — composite projects and tsc -b, incremental builds and .tsbuildinfo, source maps, compiler performance and tracing, and building with Babel, esbuild, SWC or Vite while keeping tsc --noEmit as the CI gate.

Language extensions

  • Decorators and Metadata — the TC39 standard decorators that are the current default, the legacy experimentalDecorators path that Angular and NestJS still use, and how to tell which one a project is on.

  • JSX and Frameworks — the .tsx extension and the jsx compiler option, JSX.Element vs. React.ReactNode, JSX.IntrinsicElements, and jsxImportSource; a short bridge to the framework-specific pages.

  • Async, Iterators and Generators — typing promises and async functions, Awaited<T>, Promise.all tuple typing, the iterator and generator interfaces, async iteration, and using / await using explicit resource management.

Practice

  • Type Design and Best Practices — making illegal states unrepresentable, keeping null at the perimeter, accepting wide and returning narrow, precision without overreach, branded nominal types, and exhaustiveness with never.

  • Worked Example: Migrating a Module to TypeScript — one small JavaScript module taken all the way to strict TypeScript, step by step, with the compiler output at each stage.

Reference

  • Cheat Sheet (PDF) — a single-page, printable summary of everything in this section, with a downloadable PDF.

Bibliography