Code Reference

Glossary

Typescript · Reference cheat sheet

Glossary

Typescript · Reference cheat sheet


📋 Overview

Alphabetical glossary of core TypeScript terms for types, narrowing, generics, modules, and compiler options.

🔧 Core concepts

TermDefinition
AnyAn escape-hatch type that disables most type checking for a value.
AssertionA as Type or angle-bracket cast that tells the checker to trust a type.
Branded typeA nominal-style type created by intersecting a primitive with a unique tag.
Conditional typeA type that chooses between alternatives with T extends U ? X : Y.
Const assertionas const that infers the narrowest literal and readonly types.
Declaration fileA .d.ts file that describes types for JavaScript or ambient APIs.
Discriminated unionA union of object types sharing a common literal “tag” property.
EnumA named set of related constants, numeric or string-based.
GenericA type or function parameterized by one or more type variables.
InferA keyword inside conditional types that extracts a nested type into a variable.
InterfaceA named object shape that can be extended and merged by declaration.
IntersectionA type combining members of several types with &.
KeyofAn operator producing a union of an object type’s property names.
Literal typeA type that is exactly one specific string, number, or boolean value.
Mapped typeA type that transforms each property of another type via [K in Keys].
ModuleA file with import/export that creates its own scope and type namespace.
NarrowingRefining a broad type to a more specific one via checks.
NeverThe empty type for values that never occur, such as exhausted switches.
ReadonlyA modifier or utility that makes properties immutable at the type level.
SatisfiesAn operator that checks a value against a type without widening inference.
Strict modeCompiler flags like strictNullChecks that tighten soundness.
TupleA fixed-length array type where each index may have its own type.
Type aliasA type name that refers to any type expression.
Type guardA check (including user-defined predicates) that narrows types.
TypeofAn operator that produces the type of a value in type position.
UnionA type that may be one of several alternatives joined with `
UnknownA type-safe top type that must be narrowed before use.
Utility typeBuilt-in helpers such as Partial, Pick, Omit, and Record.
ZodA popular runtime schema library often paired with TypeScript inference.

💡 Examples

Discriminated union and narrowing:

type Result =
  | { ok: true; data: string }
  | { ok: false; error: string };

function message(r: Result) {
  return r.ok ? r.data : r.error;
}

Generics and utility types:

function pickId<T extends { id: string }>(item: T): Pick<T, "id"> {
  return { id: item.id };
}

Satisfies vs assertion:

const routes = {
  home: "/",
  about: "/about",
} satisfies Record<string, `/${string}`>;

⚠️ Pitfalls

  • Confusing any (unchecked) with unknown (must narrow before use).
  • Mixing interface and type alias — interfaces merge; aliases are more flexible for unions.
  • Using a type assertion when a type guard or refactor would be safer.
  • Treating enum and union of literals as interchangeable — emit and ergonomics differ.
  • Assuming satisfies changes the value’s inferred type the same way as does — it validates without forcing the annotation type.

On this page