1. Concept library
  2. JavaScript & TypeScript
  3. Module 1: Types, values and inference

Concept

Type annotations

A colon after a name declares what type it holds. Annotate function parameters, exported values and empty collections: the places where TypeScript cannot see the intent from a value.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain what a type annotation declares and where TypeScript cannot infer the intent
  2. Annotate function parameters, return types and an empty array
  3. Spot why let items = [] is inferred as never[] and fix it

In practice

A few lines that show Type annotations doing its job.

TypeScript
function total(prices: number[], taxRate: number): number {
  return prices.reduce((sum, p) => sum + p, 0) * (1 + taxRate);
}

const seen: Set<string> = new Set();
const byId: Record<string, { name: string }> = {};
let pending: string[] = [];     // without this, [] infers as never[]

The common mistake

Watch for

Leaving an empty array or object unannotated. let items = [] is inferred as never[] in strict mode, so the first push is an error and the type never settles on what you meant.

What to know first

Your roadmap puts these before Type annotations, unless you already know them.

How it stays learned

Once a session shows you understand Type annotations, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Type annotations.

Previous in the module← Type inference