The Missing
TypeScript Reference
Learning to program, in TypeScript, from nothing.
Start with Chapter 1 →Part 1: Writing programs
Productive from the first chapter, using the tools TypeScript actually gives you.
- 1Installing a TypeScript Toolchain Without Losing Your MindreadBefore you can write a line of TypeScript, your computer needs Node and the TypeScript compiler. It's the same three steps on a Mac, on Windows, and on Linux, and you'll finish with a program you wrote and ran yourself.Project: A short greeting
- 2Your First Type ErrorreadChapter 1's error was a typo, the kind any compiler catches. This one is different, TypeScript noticing that a value has quietly changed what kind of thing it is, and stopping you before that mistake reaches JavaScript.Project: Fix the profile card
- 3Values, and the Types They Insist OnreadLast chapter showed TypeScript catching a value that changed what kind of thing it was. Here's the proper introduction to let and const, the three types you'll use constantly, and what happens when you don't give TypeScript enough to work with.Project: A receipt
- 4Strings: Text TypeScript Already UnderstandsreadEvery chapter so far has stuck text together with +. There is a nicer way to do it, plus how to measure a string, pull a piece out of it, and find something inside it.Project: An initials formatter
- 5Input: Letting the Reader Talk BackreadEvery program so far has said the same thing every time it runs, because you were the one filling in the values. This is where a program starts listening, and where you meet the one command every reader has to remember to finish typing.Project: Mad-libs
- 6Arithmetic, and the Number Type's Sharp EdgesreadChapter 3 said TypeScript has a single number type where other languages have several, and promised there was a cost. Here is the arithmetic, and here is the bill.Project: Seconds into hours, minutes and seconds
- 7Deciding Things: if, else, and TruthinessreadEvery program so far runs every line, top to bottom, no matter what. This is where a program starts choosing, and where the string that chapter 5 handed you turns out to be more dangerous than it looked.Project: Ticket pricing with real rules
- 8Loops: Doing It Again Until It's DonereadA program that can repeat itself is a different kind of thing from one that runs top to bottom. This chapter also covers what to do when a loop never stops, because yours will, probably today.Project: The number guessing game
- 9Functions: Giving Work a NamereadThree chapters have now ended by pointing at this one. Every time you found yourself copying four lines and changing one word, this was the missing piece.Project: Rules with names
- 10Arrays: A List That GrowsreadChapter 5 handed you a list and asked you to take it on trust. Here is what it actually was, how to build one yourself, and the hole in the type system that this chapter exists to show you.Project: A thousand dice
- 11Reading, Logging, and Fixing BugsreadA program that crashes tells you where to look. A program that quietly returns the wrong number tells you nothing. This chapter is about the second kind, which is the kind you will spend your time on.Project: Hunt the planted bug
- 12Objects: Things That Belong TogetherreadAn array holds many of one thing. An object holds one of many things: a title, a page count and whether you finished it, all in one value with names on the parts.Project: A reading list
- 13Copies, References, and the Trap Objects SetreadThree chapters have promised you this one. A number and an object behave completely differently when you copy them, pass them, or compare them, and not knowing which you have is the source of some genuinely baffling bugs.Project: The scoreboard that edits itself
- 14Sorting and Searching Without Writing EitherreadChapter 8 had you writing running totals and longest-so-far loops by hand. Every one of those is a method on an array already, and the sorting one has two traps in it that are worth meeting deliberately.Project: A high-score table
- 15Classes: Types You Design YourselfreadChapter 12 gave you a shape with names on the parts. A class puts the data and the functions that work on it in the same place, and lets you decide what the outside world is allowed to touch.Project: A deck of cards
- 16Constructors, and Objects That Can't Be BrokenreadChapter 15's Deck was only correct if somebody remembered to call fill on it. A constructor removes the remembering, because it runs when the object is made and there is no moment at which a half-built one exists.Project: A deck that deals itself
- 17Files: Making Your Program RememberreadEvery program you have written forgets everything the moment it ends. A file fixes that, and it is also the first place where TypeScript's guarantees genuinely stop.Project: A to-do list that survives quitting
- 18Maps: Looking Things Up by NamereadAn array finds things by position. A Map finds them by whatever you like, and it exists because the obvious alternative, a plain object, has sharp edges that only show up on real data.Project: Word frequency over a real file
- 19Validation: Assuming the WorstreadSix chapters have pointed at this one. Every place where data comes from outside your program is a place your types are guesses, and this is how you turn a guess into something you have actually checked.Project: A to-do list that cannot be broken
- 20Splitting a Program Across FilesreadEvery program so far has been one file. Real ones are not, and the moment you split one you meet a compile flag that nobody warns you about, because the program will build perfectly and then refuse to run.Project: Word frequency, in pieces
- 21Interlude: Build Something RealreadTwenty chapters of tools, and nothing new in this one. You are going to build a program that reads a file, validates it, records things, reports on them, and survives being run tomorrow.Project: The expense tracker
Part 2: Lifting the floor
Back to the machinery TypeScript and JavaScript were handling for you.
- 22Where Do the Types Go?coming soonErasure, and what's really running.
- 23Prototypes, and What This Points Tocoming soonWhy arrow functions and regular functions disagree.
- 24Closures: Functions That Remembercoming soonScope, and why closures aren't magic.
- 25The Event Loop: What Async Actually Meanscoming soonPaying off chapter 5, at last.
- 26Promises, Underneath Async and Awaitcoming soonPromise chains, and error handling around await.
- 27Generics: One Function, Any Typecoming soonThe <T> from chapter 10, explained at last.
- 28Unions, Narrowing, and Discriminated Unionscoming soonThe type system's own control flow.
- 29Structural Typing and Utility Typescoming soonWhy TypeScript cares about shape, not name.
- 30What TypeScript Can't Save You Fromcoming soonany, and why type safety isn't a guarantee.
- 31Modules, Packages, and npm Underneathcoming soonpackage.json, node_modules, and CommonJS vs ES modules.
- 32Where to Go Nextcoming soonThe TypeScript handbook, DefinitelyTyped, and reading other people's code.