Skip to content

Module Recap

Module 02 covered the building blocks of TypeScript’s type system. Every type in this module appears directly in AceIt. Here is what to carry forward.

Primitivesstring, number, and boolean are the base types for most values. With strict: true, null and undefined are separate types. If a value can be absent, declare it with a union: string | null.

Arraysstring[] and Array<string> are equivalent. TypeScript infers element types through map, filter, and find — the callback parameter is typed, the return value is typed, and find returns T | undefined because it may not find a match.

Tuples — fixed-length arrays with a specific type at each position. Use them when both length and per-position type are part of the contract.

Object types — describe object shapes with property names and types in curly braces. TypeScript uses structural typing — an object fits a type if it has at least the required properties. Accessing undeclared properties is a compile error.

Union typesstring | number means either. Use typeof to narrow before calling type-specific methods. Optional parameters (?) are shorthand for T | undefined.

Intersection typesA & B means both. The value must satisfy all properties of all combined types.

Literal types'easy' | 'medium' | 'hard' constrains a value to a specific set. let widens literals to their base type; const preserves them. Annotate let explicitly when you want both mutability and constraint.

Enumsenum ResponseCode { Success = 0, ... } names numeric (or string) constants. Members are referenced by name, not raw value, making intent readable.

Every type from this module appears in AceIt’s types.ts:

// Primitives appear in every interface property
// Arrays — the questions array and allAnswers
// Object types — formalized as interfaces in M03, but the shape is the same
export type Difficulty = 'easy' | 'medium' | 'hard'; // literal union
export enum ResponseCode { // enum
Success = 0,
NoResults = 1,
InvalidParam = 2,
TokenNotFound = 3,
TokenEmpty = 4,
}
// Union — a parameter that can be absent
export async function fetchQuestions(
amount: number,
difficulty?: Difficulty, // Difficulty | undefined
): Promise<TriviaQuestion[]> { /* ... */ }

Module 03 gives the object shapes names — TriviaQuestion, ApiResponse, HighScore — using interfaces and type aliases built on exactly the primitive, array, and object types you learned here.

TermWhat it means
PrimitiveA base type: string, number, boolean
Strict null checksnull and undefined are not assignable to other types without explicit declaration
Union typeA | B — a value that can be either type
Intersection typeA & B — a value that must satisfy both types
Literal typeA type representing exactly one value, e.g. 'easy'
Type wideningTypeScript broadening an inferred type from a literal to its base type
EnumA named set of constants with associated values
TupleA fixed-length array with a specific type at each position
Structural typingType compatibility based on shape — if it has the right properties, it fits

Module 03 — Interfaces and Type Aliases →

Module 03 gives names to the object shapes you described inline in this module. TriviaQuestion, RawQuestion, ApiResponse, and HighScore become named, reusable interfaces. You will also learn the difference between a type alias and an interface, and when each is the right choice.