REFERENCE

TypeScript Glossary

Plain-English definitions for every term you'll meet in the course, with a quick code example where it helps.

🔍

A type that accepts any value and switches off type checking for it. Anything is allowed, so mistakes are not caught.

const value: any = "Logan";

value.toFixed(); // no error, but fails at runtime

Array Type

Day 3

A type for a list where every value is the same type, written with [] after the type.

const heroes: string[] = ["Logan", "Storm"];

as const

Day 12

Tells TypeScript to infer the narrowest possible type and make everything readonly. Arrays become readonly tuples.

const hero = { name: "Logan" } as const;
// { readonly name: "Logan" }, not { name: string }

Awaited

Day 26

A utility type that gives the type a promise resolves to.

type HeroPromise = Promise<{ name: string }>;

type Resolved = Awaited<HeroPromise>;
// { name: string }

Build Time

Day 0

When your code is compiled, before it runs. Type checking happens here.

Capitalize

Day 30

A built in type that uppercases the first character of a string literal type. TypeScript has three others like it: Uppercase, Lowercase and Uncapitalize.

type Event = Capitalize<"attack">;
// "Attack"

Conditional Type

Day 29

A type that chooses between two types based on a check, written like a ternary. Applied to a union, the check runs once per member.

type Mutant = { power: string };

type IsMutant<T> = T extends Mutant ? true : false;

type Wolverine = IsMutant<{ power: "healing" }>; // true

Declaration Merging

Day 9

Declaring the same interface name more than once, which TypeScript combines into a single interface. Type aliases cannot do this.

interface Hero {
  name: string;
}

interface Hero {
  power: string;
}
// Hero now has both name and power

Default Parameter

Day 13

A parameter with a fallback value used when the argument is left out. TypeScript infers its type from that value.

function greet(name: string, title = "Agent") {
  // title is string, never undefined
}

Discriminant

Day 16

The shared property in a discriminated union whose literal type differs on each member. It is the property you check to narrow the union.

type Character =
  | { kind: "hero"; power: string }
  | { kind: "villain"; scheme: string };
// kind is the discriminant

Discriminated Union

Day 16

A union of object types that each have the same property set to a different literal type. Checking that property narrows the union to one member.

type Character =
  | { kind: "hero"; power: string }
  | { kind: "villain"; scheme: string };

function act(character: Character) {
  if (character.kind === "hero") {
    character.power; // narrowed to the hero member
  }
}

Enum

Day 20

A type that is also a set of named values, written with the enum keyword. Unlike other types it compiles to an object in JavaScript rather than being stripped out.

enum Alignment {
  Hero,
  Villain,
}

const side: Alignment = Alignment.Hero;

Enum Member

Day 20

One of the named values inside an enum. As a type, an enum accepts only its own members, never a matching string or number.

enum Alignment {
  Hero = "hero",
  Villain = "villain",
}

const a: Alignment = Alignment.Hero; // ok
const b: Alignment = "hero"; // ❌ not assignable

Exhaustiveness Check

Day 18

Assigning a value to a variable typed never after every case has been handled. It only compiles while nothing is left, so adding a new union member breaks the build.

function act(character: Character) {
  if (character.kind === "hero") return character.power;
  if (character.kind === "villain") return character.scheme;

  const remaining: never = character; // ❌ if a new kind is added
  return remaining;
}

extends

Day 8

Checks whether one type is the same as another or narrower than it. On an interface it copies every property from the one it extends, and on a type parameter it limits which types are allowed.

interface Hero {
  name: string;
}

interface Mutant extends Hero {
  power: string;
}
// Mutant has both name and power

Function Overloading

Day 27

Writing several signatures for one function, each pairing a set of parameters with its own return type, so the return type depends on what the function is given.

function summon(name: string): string;
function summon(count: number): string[];
function summon(input: string | number): string | string[] {
  return typeof input === "number" ? Array(input).fill("hero") : input;
}

Function Type

Day 27

A type that describes the shape of a function: its parameters and return type. It can be named in a type alias and reused.

type Attack = (target: string) => number;

const punch: Attack = (target) => target.length;

Generic Constraint

Day 22

A limit on which types a type parameter accepts, written with extends. It lets you use the constraint's properties inside the function.

function logName<T extends { name: string }>(item: T) {
  console.log(item.name); // allowed, every T has a name
}

Generic Function

Day 21

A function with a type parameter, so one definition works with many types. TypeScript usually infers the type from the argument.

function first<T>(items: T[]): T {
  return items[0];
}

const name = first(["Logan", "Storm"]); // T is string

Generic Type

Day 21

A type with a type parameter, so one definition describes many shapes. The type is supplied in angle brackets when used.

type Result<T> = {
  data: T;
  ok: boolean;
};

type HeroResult = Result<{ name: string }>;

Implementation Signature

Day 27

The signature on the function body underneath a set of overload signatures. It covers all of them, and is not offered to callers.

function summon(name: string): string;
function summon(count: number): string[];
function summon(input: string | number): string | string[] {
  // this is the implementation signature
  return typeof input === "number" ? Array(input).fill("hero") : input;
}

A JavaScript operator that checks whether an object has a property. TypeScript uses it to narrow a union to the members that have it.

type Hero = { power: string };
type Villain = { scheme: string };

function act(character: Hero | Villain) {
  if ("power" in character) {
    character.power; // narrowed to Hero
  }
}

Indexed Access Type

Day 24

Looks up the type of a property on an object type, written in square brackets. A union of names gives a union of those property types.

type Hero = {
  name: string;
  level: number;
};

type Name = Hero["name"]; // string
type Either = Hero["name" | "level"]; // string | number

infer

Day 29

Declares a new type variable by inferring its type from the one being checked. It can only be used inside the extends clause of a conditional type.

type ElementOf<T> = T extends Array<infer U> ? U : never;

type A = ElementOf<string[]>; // string

Interface

Day 8

A named object type, written with the interface keyword. Unlike a type alias it can only describe object shapes.

interface Hero {
  name: string;
  level: number;
}

Intersection Type

Day 7

A type that combines two or more types into one, written with &. The value needs everything from all of them.

type Named = { name: string };
type Powered = { power: string };

type Hero = Named & Powered;

const logan: Hero = { name: "Logan", power: "healing" };

Key Remapping

Day 30

Renaming the keys of a mapped type with an as clause, usually with a template literal type. This as renames a key and does not assert a type.

type EventHandlers<T> = {
  [K in keyof T as `on${Capitalize<string & K>}`]: () => string;
};

keyof

Day 23

Gives a union of an object type's property names.

type Hero = {
  name: string;
  level: number;
};

type HeroKey = keyof Hero;
// "name" | "level"

Literal Type

Day 11

A type that allows only one exact value.

type Alignment = "hero";

const side: Alignment = "hero"; // only this value is allowed

Literal Union

Day 11

A union of literal types, used to list every allowed value. Unlike string, it rejects anything not on the list.

type Alignment = "hero" | "villain";

const side: Alignment = "hero";
const typo: Alignment = "heros"; // ❌ not assignable

Mapped Type

Day 28

A type that builds an object type by looping over a union of keys and giving each key a type. The built in utility types are written this way.

type Hero = { name: string; level: number };

type ReadonlyHero = {
  readonly [K in keyof Hero]: Hero[K];
};
// { readonly name: string; readonly level: number }

Mapping Modifier

Day 28

A ? or readonly added to the key of a mapped type, applying to every generated property. A minus sign in front removes it instead.

type MyPartial<T> = {
  [K in keyof T]?: T[K]; // adds optional
};

type MyRequired<T> = {
  [K in keyof T]-?: T[K]; // removes optional
};

Narrowing

Day 14

TypeScript reducing a value from a wider type to a more specific one, based on a check in your code. The narrowed type applies inside that branch.

function show(value: string | number) {
  if (typeof value === "string") {
    value.toUpperCase(); // value is string here
  }
}

never

Day 18

The type of a value that can never exist. It is produced by an impossible type, or when narrowing has ruled out every member of a union.

type Impossible = string & number; // never

Object Type

Day 5

A type describing the shape of an object: which properties it has and what type each one is.

type Hero = {
  name: string;
  level: number;
};

Omit

Day 25

A utility type that builds a new object type with the named properties removed.

type Hero = { name: string; level: number; power: string };

type Summary = Omit<Hero, "power">;
// { name: string; level: number }

Optional Parameter

Day 13

A parameter marked with ?, which can be left out when the function is called. Its type is the declared type or undefined.

function greet(name: string, title?: string) {
  // title is string | undefined
}

greet("Logan"); // ok

Optional Property

Day 5

A property marked with ?, which may be missing. Reading it gives either its type or undefined.

type Hero = {
  name: string;
  power?: string; // string | undefined
};

const logan: Hero = { name: "Logan" }; // ok

Overload Signature

Day 27

One of the signatures written above an overloaded function. TypeScript picks the first one matching the arguments and types the call from it.

function summon(name: string): string; // overload signature
function summon(count: number): string[]; // overload signature

Parameters

Day 26

A utility type that gives a tuple type of a function's parameters. The parameter names appear as labels on the tuple elements.

function recruit(name: string, level: number) {}

type RecruitArgs = Parameters<typeof recruit>;
// [name: string, level: number]

Partial

Day 25

A utility type that makes every property of a type optional.

type Hero = { name: string; level: number };

type Draft = Partial<Hero>;
// { name?: string; level?: number }

Pick

Day 25

A utility type that builds a new object type from only the named properties.

type Hero = { name: string; level: number; power: string };

type Summary = Pick<Hero, "name" | "level">;
// { name: string; level: number }

Primitive Type

Day 1

One of JavaScript's built in basic types: string, number, boolean, null, undefined, symbol and bigint.

Readonly Modifier

Day 5

Marks a property so it cannot be reassigned after the object is created.

type Hero = {
  readonly name: string;
};

const logan: Hero = { name: "Logan" };
logan.name = "Wolverine";
// ❌ Cannot assign to 'name' because it is a read-only property

Record

Day 26

A utility type that builds an object type from a set of keys and one value type.

type Alignment = "hero" | "villain";

type Counts = Record<Alignment, number>;
// { hero: number; villain: number }

Required

Day 25

A utility type that makes every property of a type required, removing any ? markers.

type Draft = { name?: string; level?: number };

type Hero = Required<Draft>;
// { name: string; level: number }

Rest Parameter

Day 13

A parameter written with ... that collects any remaining arguments into an array.

function assemble(leader: string, ...team: string[]) {
  // team is string[]
}

assemble("Logan", "Storm", "Rogue");

Return Type

Day 13

The type of the value a function gives back, annotated after the brackets. It is usually inferred rather than written.

function getLevel(name: string): number {
  return name.length;
}

ReturnType

Day 26

A utility type that gives the return type of a function type. Often used with typeof to read the return type of an existing function.

function getHero() {
  return { name: "Logan", level: 9 };
}

type Hero = ReturnType<typeof getHero>;
// { name: string; level: number }

Runtime

Day 0

When your code actually runs. No type information exists at this point, because the compiler has already removed it.

satisfies

Day 19

Checks a value against a type without replacing the type that was inferred. Unlike an annotation it does not widen the value.

type Hero = { level: string | number };

const hero = { level: 9 } satisfies Hero;
// level stays number, not string | number

hero.level.toFixed(); // ok

Static Typing

Day 0

Types are checked at build time, before the code runs, rather than while it runs.

Structural Typing

Day 10

Types are compared by their shape rather than by name. Having the required properties is enough, no matter what the type was called or where it came from.

type Hero = { name: string };

const logan = { name: "Logan", claws: true };

const hero: Hero = logan; // ok, it has a name

Superset

Day 0

A language that contains another entirely. Every JavaScript file is already valid TypeScript, because TypeScript only adds to JavaScript rather than changing it.

Template Literal Type

Day 30

A string literal type built from other types using backtick syntax. Interpolating a union produces every combination.

type Alignment = "hero" | "villain";

type Label = `marvel-${Alignment}`;
// "marvel-hero" | "marvel-villain"

Tuple

Day 3

An array type with a fixed length and a specific type at each position.

const hero: [string, number] = ["Logan", 9];

Type Alias

Day 6

A name for a type, written with the type keyword, so the type can be reused instead of written out each time. It can name any type, not just object shapes.

type Hero = {
  name: string;
  level: number;
};

type Level = string | number;

Type Annotation

Day 1

A type you write yourself, added after a colon following the name. It tells TypeScript what type something is instead of letting it work it out.

const name: string = "Logan";
const level: number = 9;

Type Assertion

Day 19

Telling TypeScript to treat a value as a particular type, written with as. It checks nothing and converts nothing.

const stored = JSON.parse(raw) as { name: string };

stored.name.toUpperCase(); // allowed because you asserted the type

Type Error

Day 0

An error reported by the compiler when a value is used in a way its type does not allow. It appears before the code runs, not while it runs.

Type Guard

Day 15

A check that narrows a type. typeof, in, Array.isArray and undefined checks are built in, and you can write your own using a type predicate.

function act(value: string | number) {
  if (typeof value === "string") {
    value.toUpperCase(); // narrowed to string
  }
}

Type Inference

Day 2

TypeScript working out a type from the value rather than being told it by an annotation. It is the default.

const name = "Logan"; // inferred as string

Type Parameter

Day 21

A placeholder for a type, declared in angle brackets, that stands in for a type decided when the code is used.

function first<T>(items: T[]): T {
  return items[0];
}
// T is the type parameter

Type Predicate

Day 15

A return type written value is Type, which declares that the argument is of that type when the function returns true. Without it, nothing narrows at the call site.

function isHero(value: unknown): value is Hero {
  return typeof value === "object" && value !== null && "power" in value;
}

Type System

Day 0

The rules TypeScript uses to decide what type a value has and which operations are allowed on it.

typeof

Day 23

Used in a type position, reads a variable and produces its type. This is separate from the JavaScript typeof operator that returns a string at runtime.

const roster = { name: "Logan", level: 9 };

type Roster = typeof roster;
// { name: string; level: number }

TypeScript Compiler

Day 0

The tool that checks your types, reports any errors, then removes the types and outputs plain JavaScript.

Union Type

Day 4

A type made of several types, where the value can be any one of them, written with | between them.

type Level = string | number;

const rank: Level = 9; // a string would also be allowed

unknown

Day 17

A type that accepts any value but must be narrowed before it can be used. The safe alternative to any.

const value: unknown = "Logan";

value.toUpperCase();
// ❌ 'value' is of type 'unknown'

if (typeof value === "string") {
  value.toUpperCase(); // ok
}

Utility Type

Day 25

A generic type built into TypeScript that builds a new type from one you already have, saving you writing a near duplicate by hand.

type Hero = { name: string; level: number };

type Draft = Partial<Hero>;
// { name?: string; level?: number }