Skip to content
LumenaryAcademy

Lumenary CS · Programming languages

TypeScript

JavaScript with a type system: catch mistakes before your code runs, describe your data precisely, and work confidently in large code bases.

TypeScript is JavaScript with static types. You write ordinary JavaScript plus annotations that describe what your values are; the TypeScript compiler checks every use against those descriptions before the program runs, then removes the annotations and leaves plain JavaScript that runs anywhere JavaScript does. Microsoft released it in 2012, and it has become the usual way to write JavaScript professionally, from web front ends built with React, Angular or Vue to Node.js servers and tools. This course covers why and how the type system works, basic and literal types, interfaces and type aliases, unions and narrowing, functions and overloads, generics, utility, mapped and conditional types, classes, modules and declaration files, the strictness options, and how to bring TypeScript into existing JavaScript projects and frameworks, ending with a complete small project.

It assumes you can already program in JavaScript: take the JavaScript course in this series first, or come with equivalent experience. That in turn assumes the Start level of Lumenary CS or equivalent: you know what a variable, a loop and a function are.

To run the examples, install Node.js and then TypeScript with npm install --save-dev typescript in a project folder (installation options). The official TypeScript Playground runs TypeScript in your browser with nothing to install, and shows the JavaScript it produces and the type of anything you point at. Every complete program in these lessons is type-checked by Lumenary's test suite with tsc --strict (TypeScript 5.9) and then run with Node 22; the output shown is what it printed. Code that is meant to show a type error is shown separately, with the compiler's actual message.

AI-draftedAwaiting review by a computer scientist
  • Chloe · The Designer
    “Why is the language built this way?”
  • Margaret · The Profiler
    “What does it print, and what does it cost?”
  • Gideon · The Language Lawyer
    “What exactly does the language guarantee?”

Foundations · 4 lessons

Types for JavaScript

Why TypeScript exists and how its compiler works, the basic and literal types, object types written as interfaces and type aliases, and unions with the narrowing that makes them safe.

  1. 1Why TypeScriptWhat a static type checker adds to JavaScript, how TypeScript came to be, and how to compile and run your first program. 50 min
  2. 2Basic and literal typesPrimitives, arrays and tuples, the special types any, unknown and never, and the literal types that make TypeScript precise. 55 min
  3. 3Interfaces and type aliasesDescribing the shape of objects, with optional and read-only properties, extension and intersection, dictionaries, and how to choose between interface and type. 50 min
  4. 4Unions and narrowingValues that can be one of several things, and how TypeScript follows your checks to know which one you have. 55 min

Practice · 3 lessons

Typing real code

Functions and overloads, generics that keep code reusable without losing type information, and classes, modules and the declaration files that describe JavaScript libraries.

  1. 5Typing functionsParameters and return types, optional, default and rest parameters, function types and callbacks, overloads, and this. 55 min
  2. 6GenericsFunctions, types and classes with type parameters, constraints with extends and keyof, and the habits that keep generic code readable. 60 min
  3. 7Classes, modules and declaration filesTyped classes with access modifiers, abstract members and interfaces; ES modules and type-only imports; and the .d.ts files that describe JavaScript to the compiler. 60 min

Professional · 2 lessons

The type system at full strength

Utility, mapped and conditional types for computing types from types, then the strictness options, migrating JavaScript projects, frameworks and runtime validation, ending with a complete project.

  1. 8Utility, mapped and conditional typesComputing types from other types, so that one definition drives the rest, and knowing when to stop. 65 min
  2. 9TypeScript in practiceThe strictness options, bringing TypeScript into JavaScript projects and frameworks, validating data at the boundary, and a complete project. 75 min

Further reading and resources

  • TypeScript website · MicrosoftDownloads, documentation and news.
  • The TypeScript Handbook · MicrosoftThe official guide to the language; TypeScript has no separate formal specification, so the handbook and the compiler define it.
  • TypeScript Playground · MicrosoftWrite TypeScript in the browser and see its errors, inferred types and JavaScript output.
  • TSConfig reference · MicrosoftEvery compiler option, with examples.
  • TypeScript on GitHub · MicrosoftThe compiler's source, issue tracker and design discussions.
  • The TypeScript blog · MicrosoftRelease announcements, which explain each new feature in detail.