Lessons
Lessons
TypeScript adds types to JavaScript and finds mistakes before your program runs. You will build the inventory and quest log of a role-playing game.
Lessons
Lesson 1
Let TypeScript check your JavaScript: read its error messages and see the types it infers.
Worth 85 XP
Lesson 2
Annotate variables as string, number or boolean, and type arrays like string[] and tuples.
Worth 140 XP
Lesson 3
Add types to parameters and return values, and use void, optional parameters, map and filter.
Worth 150 XP
Checkpoint
Score an archery contest: count hits and points, award medals and announce the winner.
Worth 30 XP
Output
Archer: KiraHits: 5 of 6 arrowsPoints: 40Bullseyes: 2 (bonus 10)Score: 50Medal: goldArcher: BrunoHits: 4 of 5 arrowsPoints: 36Bullseyes: 2 (bonus 10)Score: 46Medal: goldWinner: Kira
Lesson 5
Describe objects with type and interface, including optional and readonly properties.
Worth 160 XP
Lesson 6
Combine types like string | number, narrow them with typeof, and handle null and undefined.
Worth 145 XP
Lesson 7
Write discriminated unions, cover every kind with switch and never, and use Record for tables.
Worth 100 XP
Checkpoint
Keep a blacksmith's order book: work out prices, regulars' discounts and engraving costs.
Worth 30 XP
Output
Kira: forging, Arrowheads (steel), 30 gold (5 off)Bruno: repair, Battle Axe, 15 gold (new customer)Lena: sharpening, Dagger, 8 goldBruno: forging, Shield (bronze), 20 gold (new customer)Kira: engraving KIRA, Elven Bow, 7 gold (5 off)Total: 80 goldForging: 2, repairs: 1, sharpening: 1, engraving: 1
Lesson 9
Write functions and types that work for every type with <T>, and constrain T with extends.
Worth 120 XP
Lesson 10
Create classes with a constructor, methods and private fields, and build on them with extends.
Worth 115 XP
Checkpoint
Program an adventurers' bank: account classes, deposits, withdrawals and a vault with a fee.
Worth 30 XP
Output
Kira: 120 goldBruno: 40 goldLena: 75 gold (vault)The bank holds 235 gold.Bruno deposits 30 gold. Balance: 70Kira withdraws 50 gold. Balance: 70Bruno can't withdraw 100 gold: not enough goldMira can't deposit 10 gold: no accountLena withdraws 60 gold. Balance: 13Kira: 70 goldBruno: 70 goldLena: 13 gold (vault)The bank holds 153 gold.
Lesson 12
Turn existing types into new ones with Partial, Pick and Omit, and protect data with Readonly.
Worth 110 XP
Lesson 13
Build Kira's inventory and quest log with discriminated unions, a generic search and Record.
Worth 95 XP
Output
Kira the ranger, level 3, health 34/50, gold 120Inventory:- Healing Potion (heals 20)- Silver Sword (damage 12)- Old Key (opens the crypt)- Scroll of Light (spell: Light)Kira drinks Healing Potion: health 50/50Kira equips Silver SwordKira has no Dragon EggQuests:[done] Wolves in the Woods: +50 gold[open] The Lost Crown[failed] Save the Miller: the mill burned down[done] The Goblin Bridge: +30 gold
TypeScript adds types to JavaScript and finds mistakes before your program runs. The course goes from basic types and functions to object types, unions and narrowing, modeling data, generics and classes, and ends with utility types: the tools you meet in every larger TypeScript project.
It's meant for those who know JavaScript. You write programs for an archery contest, a blacksmith and an adventurers' bank, and in the final project a ranger's inventory and quest log. Your code is type-checked and run right in the browser.
To run code of your own, outside the exercises: TypeScript playground