Learn TypeScript through test-driven development with two learning paths
Learn TypeScript through test-driven development, inspired by the famous Ruby Koans. This repository offers two distinct learning experiences:
- Basic Koans (
basic_koans/directory) - Core TypeScript concepts for beginners - Advanced Koans (
advanced_koans/directory) - Professional-grade, comprehensive learning
The TypeScript Koans walk you along the path to enlightenment in order to learn TypeScript. The goal is to learn the TypeScript language, syntax, structure, and development practices through test-driven development.
Perfect for beginners and those learning core TypeScript concepts
- 12 fundamental modules covering essential TypeScript features
- Clear, focused learning of basic concepts
- Straightforward explanations of core language features
- Beginner-friendly progression from basics to intermediate concepts
Comprehensive, professional-grade learning experience
- 11,313+ lines of educational content (5.5x expansion from basic)
- 86+ detailed tests with comprehensive concept explanations
- 50+ CONCEPT headers explaining WHY, not just HOW
- 500+ real-world patterns used in production systems
- Expert-level coverage from basics to advanced type-level programming
β Jump to Advanced Koans for the comprehensive learning experience.
The basic koans (in basic_koans/ directory) are broken out into focused modules, each containing core TypeScript concepts:
about-asserts.ts- Assertions and basic testing conceptsabout-types.ts- TypeScript's type system fundamentalsabout-strings.ts- String manipulation and template literalsabout-arrays.ts- Array operations and methodsabout-functions.ts- Functions, arrow functions, and basic patternsabout-objects.ts- Object literals and basic object operationsabout-classes.ts- Classes, inheritance, and basic OOPabout-interfaces.ts- Interface definitions and structural typingabout-enums-unions.ts- Enums and union typesabout-generics.ts- Generic functions and classesabout-async-await.ts- Promises and async/await basicsabout-advanced-types.ts- More sophisticated TypeScript features
They are presented in order in the path-to-enlightenment.ts file.
If you want comprehensive, production-ready TypeScript knowledge with detailed concept explanations, real-world patterns, and expert-level coverage, check out the Advanced TypeScript Koans directory.
Each koan builds up your knowledge of TypeScript and builds upon itself. It will stop at the first place you need to correct.
Some koans simply need to have the correct answer substituted for an incorrect one. Some, however, require you to supply your own answer. If you see the method __() or ___(), it is a hint to you to supply your own code in order to make it work correctly.
- Node.js - Version 16 or later
- Yarn - Package manager (recommended over npm for this project)
To check your installations:
node --version # Should be 16.0.0 or later
yarn --version # Any recent versionIf you don't have Yarn installed:
npm install -g yarnReady to master TypeScript? This repository has been restructured into two learning paths. Follow these simple steps to begin your journey to enlightenment!
git clone https://github.com/yangtheman/ts_koans.git
cd ts_koansFor Basic Koans (beginners):
cd basic_koans
yarn installFor Advanced Koans (comprehensive learning):
cd advanced_koans
yarn installFor Basic Koans:
# From basic_koans/ directory
yarn generate
yarn install:koans # Installs dependencies in koans/ subdirectoryFor Advanced Koans:
# From advanced_koans/ directory
yarn generate
yarn install:koans # Installs dependencies in koans/ subdirectoryThis creates a koans/ directory within your chosen path with the student version of the files (with solutions removed and blanks to fill in).
For Basic Koans:
# From basic_koans/ directory
yarn test:koans # Begin your path to enlightenmentFor Advanced Koans:
# From advanced_koans/ directory
yarn test:koans # Begin your comprehensive journeyπ― You're now ready to learn TypeScript! Choose your path:
- Basic Koans: 12 fundamental modules for solid foundations
- Advanced Koans: 86+ comprehensive tests across 12 enhanced modules with detailed explanations!
The first test will fail, showing you exactly what to fix. Each failure is a step closer to mastery.
You can run the tests using yarn test from the appropriate koans directory (basic_koans/koans/ or advanced_koans/koans/).
In test-driven development the mantra has always been red, green, refactor. Write a failing test and run it (red), make the test pass (green), then look at the code and consider if you can make it any better (refactor).
While walking the path to TypeScript enlightenment you will need to run the koan and see it fail (red), make the test pass (green), then take a moment and reflect upon the test to see what it is teaching you and improve the code to better communicate its intent (refactor).
The very first time you run the koans you will see the following output:
π Welcome to TypeScript Koans!
The path to TypeScript enlightenment begins...
==================================================
β about-asserts.ts has damaged your karma.
The TypeScript Master says:
You have not yet reached enlightenment.
The answers you seek...
Assertion failed
Please meditate on the following code:
about-asserts.ts
Your path thus far [ββββββββββββββββββββββββββββββββββββββββββββββββββ] 0/86 (0%)
"Mountains are merely mountains" ποΈ
You have come to your first stage. Open the about-asserts.ts file and look at the first test:
// Learn: Assertions are the foundation of understanding in koans
// assert() checks if a condition is true and fails the test if it's false
// This is your first step: make the assertion pass by changing __() to true
// The path to enlightenment begins with acknowledging truth
test_assert_truth(): void {
this.assert(this.__()); // Fill in the blank with true
}Replace the this.__() with true and re-run the test. After you are done, think about what you are learning. Each test includes detailed CONCEPT explanations that teach you not just what to do, but WHY TypeScript works the way it does.
In this case the goal is for you to see that if you pass a value to the assert method, it will either ensure it is true and continue on, or fail if the statement is false.
The normal path to enlightenment looks like this:
For Basic Koans:
cd basic_koans
yarn test:koans
# edit the koans files
yarn test:koans
# edit the koans files
yarn test:koans
# etcFor Advanced Koans:
cd advanced_koans
yarn test:koans
# edit the koans files
yarn test:koans
# edit the koans files
yarn test:koans
# etcyarn build- Compile TypeScript source filesyarn generate- Generate student koans from sourceyarn test- Build and run the complete (solution) versionyarn clean- Remove generated filesyarn reset- Clean and regenerate koansyarn watch- Watch for changes and auto-run testsyarn install:koans- Install dependencies in student koans directoryyarn build:koans- Build the student koansyarn test:koans- Run the student koans testsyarn clean:koans- Clean student koans compiled files
yarn build- Compile TypeScript source filesyarn generate- Generate student koans from sourceyarn test- Build and run the complete (solution) versionyarn clean- Remove generated filesyarn reset- Clean and regenerate koansyarn watch- Watch for changes and auto-run testsyarn install:koans- Install dependencies in student koans directoryyarn build:koans- Build the student koansyarn test:koans- Run the student koans testsyarn clean:koans- Clean student koans compiled files
yarn build- Compile the student koansyarn test- Run the koans (this is your main learning command!)yarn clean- Remove compiled files
typescript-koans/
βββ basic_koans/ # Basic learning path
β βββ src/ # Source files with solutions
β β βββ koan.ts # Base koan framework
β β βββ about-asserts.ts # Basic assertions
β β βββ about-types.ts # Basic type system
β β βββ ... (other koans)
β β βββ path-to-enlightenment.ts # Main runner
β β βββ generate-koans.ts # Generator script
β βββ koans/ # Generated student files
β β βββ *.ts # Koan files with blanks to fill
β β βββ package.json # Student dependencies
β β βββ tsconfig.json # Student TypeScript config
β βββ lib/ # Compiled JavaScript (generated)
β βββ package.json # Basic koans configuration
β βββ tsconfig.json # Basic koans TypeScript config
βββ advanced_koans/ # Advanced learning path
β βββ src/ # Comprehensive source files
β β βββ koan.ts # Enhanced koan framework
β β βββ about-asserts.ts # Advanced assertions (1,244 lines)
β β βββ about-types.ts # Comprehensive types (449 lines)
β β βββ ... (enhanced koans with detailed concepts)
β β βββ path-to-enlightenment.ts # Main runner
β β βββ generate-koans.ts # Generator script
β βββ koans/ # Generated student files
β βββ lib/ # Compiled JavaScript (generated)
β βββ package.json # Advanced koans configuration
β βββ tsconfig.json # Advanced koans TypeScript config
β βββ README.md # Advanced koans specific guide
βββ lib/ # Root compiled JavaScript (legacy)
βββ package.json # Root project configuration
βββ tsconfig.json # Root TypeScript configuration
βββ README.md # This file (main guide)
By completing the basic koans, you'll gain solid understanding of core TypeScript concepts:
- Type annotations and type inference
- Primitive types:
string,number,boolean,bigint,symbol - Arrays, objects, and basic data structures
- Functions, arrow functions, and parameter patterns
- Classes, inheritance, and access modifiers
- Interfaces and structural typing
- Enums, union types, and basic type manipulation
- Generic functions and classes
- Async/await and Promise handling
- Advanced types and utility types
- Type guards and type assertions
- Module systems and namespaces
- Basic error handling patterns
For comprehensive, professional-level TypeScript mastery, including:
- Advanced type-level programming
- Real-world architectural patterns
- Production-ready development practices
- Expert-level debugging and validation techniques
- 11,313+ lines of detailed educational content
β Continue with the Advanced TypeScript Koans
- Read the comments carefully - Each test includes explanations of core concepts
- Use
__()and___()as placeholders - Replace these with the correct values - Take your time - Understanding is more important than speed
- Experiment beyond the tests - Try different solutions and explore edge cases
- Read the TypeScript handbook - typescriptlang.org
- Study the source files - Complete solutions in
src/show the answers
- Focus on core concepts - Build a solid foundation
- Practice regularly - Consistent practice builds understanding
- Move to advanced koans - For comprehensive, professional-level learning
Ready for production-level TypeScript mastery? The Advanced TypeScript Koans provide:
- Comprehensive concept explanations (WHY, not just HOW)
- Real-world architectural patterns
- Expert-level debugging and validation techniques
- 11,313+ lines of detailed educational content
"Cannot find module" errors:
Make sure you've run yarn install in the appropriate directories:
- Basic koans:
cd basic_koans && yarn install - Advanced koans:
cd advanced_koans && yarn install - Student koans: Use
yarn install:koansfrom the basic_koans or advanced_koans directory, OR manuallycd basic_koans/koans && yarn install/cd advanced_koans/koans && yarn install
TypeScript compilation errors: The koans are designed to fail initially. Follow the error messages to understand what needs to be fixed.
Tests not running: Ensure you're in the correct koans directory:
- Basic:
basic_koans/koans/ - Advanced:
advanced_koans/koans/
- Check the TypeScript Documentation
- Review the source files in
src/for complete solutions - Look at the error messages - they often contain the answer
This project offers both basic and advanced learning paths. If you'd like to contribute:
- Fork the repository
- For basic koans: Focus on clear, fundamental concepts
- For advanced koans: Maintain the educational quality standard with detailed CONCEPT headers
- Test your changes thoroughly
- Submit a pull request
A special thanks to Jim Weirich and Joe O'Brien for creating the original Ruby Koans, which inspired this TypeScript version.
- Basic Koans (
basic_koans/directory): Core TypeScript concepts for beginners - Advanced Koans: Comprehensive, professional-grade learning with 11,313+ lines of content
- Original Ruby Koans: github.com/edgecase/ruby_koans
- TypeScript Handbook: typescriptlang.org/docs
- TypeScript Deep Dive: basarat.gitbook.io/typescript
This project is licensed under the MIT License - see the LICENSE file for details.
π± New to TypeScript? Start with Basic TypeScript Koans for solid fundamentals.
π Ready for mastery? Jump to Advanced TypeScript Koans for comprehensive, professional-level learning.
"The path of the TypeScript developer begins with a single test." π§ββοΈ
Your journey to TypeScript enlightenment starts here! β¨