ctrl + Q ACADEMY • ARCHITECTURE CORE

Typed JavaScript: TypeScript

Catch bugs before you run your code by adding a type system on top of JavaScript.

Tier 1: Foundations
Basics

What TypeScript Adds to JavaScript

TypeScript is a superset of JavaScript that adds optional static types, compiled ("transpiled") down to plain JavaScript before it runs. The compiler catches type mismatches — like passing a string where a number is expected — before your code ever runs, instead of failing at runtime.

basics.ts
let age: number = 29;
let name: string = "Ada";
let isActive: boolean = true;

// age = "twenty-nine"; // Compile error: string is not assignable to number
Basics

Typing Function Parameters & Return Values

Annotating a function's parameters and return type documents its contract and lets the compiler flag incorrect calls immediately, right in your editor.

functions.ts
function add(a: number, b: number): number {
  return a + b;
}

add(2, 3);      // OK
// add(2, "3"); // Compile error
Tier 2: Structuring Data
Core

Interfaces & Type Aliases

An interface (or type) describes the shape of an object: which properties it has and their types. This makes it clear exactly what a function or component expects, and the compiler enforces it everywhere that shape is used.

interfaces.ts
interface User {
  id: number;
  name: string;
  email?: string; // optional property
}

function greetUser(user: User): string {
  return `Hello, ${user.name}!`;
}
Core

Union Types & Type Narrowing

A union type (string | number) says a value can be one of several types. Type narrowing — using typeof, instanceof, or equality checks — lets TypeScript figure out exactly which type you're working with inside an if branch.

union.ts
function formatId(id: string | number): string {
  if (typeof id === "number") {
    return id.toFixed(0);
  }
  return id.trim();
}
Tier 3: Professional Practices
Critical Spec

Generics

Generics let a function or type work with any type while still preserving type safety, instead of writing near-duplicate code for every type or giving up and using any. The type parameter (commonly T) is filled in at the call site.

generics.ts
function firstItem(items: T[]): T | undefined {
  return items[0];
}

const num = firstItem([1, 2, 3]);        // inferred as number
const word = firstItem(["a", "b", "c"]); // inferred as string
Professional

Why Teams Adopt TypeScript

On top of catching bugs early, typed code gives editors much better autocomplete, makes large refactors safer (the compiler flags every place a changed type breaks), and serves as always-up-to-date documentation of your data shapes — a major reason it's the default choice for most professional JavaScript/React codebases today.

Quiz: What is the main benefit of TypeScript's static type system?
Final Assessment

Ready to test what you've learned?

Take the TypeScript certification exam — 8 questions, 70% to pass. Passing unlocks a downloadable certificate with your name on it.