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.
What you learned
Section titled “What you learned”Primitives — string, 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.
Arrays — string[] 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 types — string | number means either. Use typeof to narrow before calling type-specific methods. Optional parameters (?) are shorthand for T | undefined.
Intersection types — A & 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.
Enums — enum ResponseCode { Success = 0, ... } names numeric (or string) constants. Members are referenced by name, not raw value, making intent readable.
How this connects to AceIt — types.ts
Section titled “How this connects to AceIt — types.ts”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 absentexport 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.
Key terms
Section titled “Key terms”| Term | What it means |
|---|---|
| Primitive | A base type: string, number, boolean |
| Strict null checks | null and undefined are not assignable to other types without explicit declaration |
| Union type | A | B — a value that can be either type |
| Intersection type | A & B — a value that must satisfy both types |
| Literal type | A type representing exactly one value, e.g. 'easy' |
| Type widening | TypeScript broadening an inferred type from a literal to its base type |
| Enum | A named set of constants with associated values |
| Tuple | A fixed-length array with a specific type at each position |
| Structural typing | Type compatibility based on shape — if it has the right properties, it fits |
What is next
Section titled “What is next”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.