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
readonlymembers,any/unknown/void/never, and literal types withas 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 —
interfacevs.typeand 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,
voidandneverreturns,thisparameters, 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 andnoUncheckedIndexedAccess, tuples with optional, rest and labelled elements, and variadic tuple types. -
Classes — typed fields and accessors, initialization checking, compile-time visibility vs. real
#private,staticandabstractmembers, parameter properties,implementsvs.extends,override, polymorphicthis, and mixins.
Generics and type-level programming
-
Generics — generic functions, interfaces, classes and type aliases, constraints and defaults, inference and how to guide it,
consttype parameters andNoInfer<T>, and the golden rule for when a type parameter earns its place. -
Type Manipulation —
keyof, thetypeoftype query, indexed access, conditional types andinfer, 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 ofExclude/Extract/NonNullable, the function and class reflection types,Awaited, and how each one is implemented. -
Type Assertions and Modifiers —
asand its limits, non-null and definite-assignment assertions,constassertions, thesatisfiesoperator, andanyvs.unknownvs.neveras the top and bottom types. -
Enums and Literal Alternatives — numeric, string and
constenums, the non-erasable caveat, and the string-literal-union plusas constobject alternative.
Modules, declarations and JavaScript interop
-
Modules — ES module syntax and dynamic import,
import typeandverbatimModuleSyntax, themoduleResolutionvalues,pathsmapping, CommonJS/ESM interop, ambient module declarations, and why to prefer modules over namespaces. -
Declaration Files — what a
.d.tsis,declareand ambient declarations, consuming bundled types vs.@types/*from DefinitelyTyped, module and global augmentation, and publishing types with your package. -
JavaScript Interop and Migration —
allowJsandcheckJs, the// @ts-checkfamily of comment directives, JSDoc as a type syntax, the migration ladder from plain JavaScript to fullstrict, and preferring ECMAScript features over TypeScript-only ones.
Configuration and build
-
tsconfig.json and Compiler Options —
tsc --init,files/include/exclude, shared config bases, thestrictfamily and the linting-adjacent flags, the emit options, and the diagnostic flags. -
Project References and Build —
compositeprojects andtsc -b, incremental builds and.tsbuildinfo, source maps, compiler performance and tracing, and building with Babel, esbuild, SWC or Vite while keepingtsc --noEmitas the CI gate.
Language extensions
-
Decorators and Metadata — the TC39 standard decorators that are the current default, the legacy
experimentalDecoratorspath that Angular and NestJS still use, and how to tell which one a project is on. -
JSX and Frameworks — the
.tsxextension and thejsxcompiler option,JSX.Elementvs.React.ReactNode,JSX.IntrinsicElements, andjsxImportSource; a short bridge to the framework-specific pages. -
Async, Iterators and Generators — typing promises and
asyncfunctions,Awaited<T>,Promise.alltuple typing, the iterator and generator interfaces, async iteration, andusing/await usingexplicit resource management.
Practice
-
Type Design and Best Practices — making illegal states unrepresentable, keeping
nullat the perimeter, accepting wide and returning narrow, precision without overreach, branded nominal types, and exhaustiveness withnever. -
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
-
typescriptlang.org/docs — the official TypeScript documentation, the source every page in this section is written and verified against; see in particular the Handbook, Everyday Types, Narrowing, More on Functions, Object Types, Generics, Creating Types from Types, Utility Types, Modules and the Modules deep-dive, Declaration Files, and the TSConfig Reference.
-
the TypeScript Playground, the official cheat sheets, Download, and the release notes / the TypeScript dev blog.
-
microsoft/TypeScript — source and issue tracker; DefinitelyTyped and the
@typessearch. -
Goldberg, Josh. Learning TypeScript — Enhance Your Web Development Skills Using Type-Safe JavaScript. O’Reilly Media, 2022. ISBN 978-1-098-11033-8. Consulted as part of the bibliography for this section (targets roughly TypeScript 4.7) — see the publisher’s book page, oreilly.com, and the author’s companion site with a free online edition at learningtypescript.com.
-
Cherny, Boris. Programming TypeScript — Making Your JavaScript Applications Scale. O’Reilly Media, 2019. ISBN 978-1-492-03765-1. Consulted as part of the bibliography for this section (targets roughly TypeScript 3.x) — see the publisher’s book page and oreilly.com.
-
Vanderkam, Dan. Effective TypeScript — 83 Specific Ways to Improve Your TypeScript, 2nd ed. O’Reilly Media, 2024. ISBN 978-1-098-15506-3. Consulted as part of the bibliography for this section (updated for TypeScript 5.x) — see the publisher’s book page, oreilly.com, and the author’s companion site at effectivetypescript.com.
-
MDN Web Docs — the underlying JavaScript language and runtime APIs the type layer describes; cross-linked where used, together with the existing JavaScript Development, TypeScript with React, and TypeScript Essentials for Angular pages on this site.