Skip to content

Instantly share code, notes, and snippets.

@chrisl8888
Last active March 10, 2025 19:58
Show Gist options
  • Save chrisl8888/4348edca629d03be8d84f3ca79511dc3 to your computer and use it in GitHub Desktop.
Save chrisl8888/4348edca629d03be8d84f3ca79511dc3 to your computer and use it in GitHub Desktop.
Typescript TDD course in 4 parts

Intro to TypeScript for JavaScript Developers with Test-Driven Development (TDD)

Course Overview

This course introduces JavaScript developers to TypeScript while emphasizing Test-Driven Development (TDD). It focuses on leveraging TypeScript's static typing and tooling to improve software reliability and maintainability.

Prerequisites

  • Familiarity with JavaScript (ES6+)
  • Basic understanding of unit testing (Jest, Mocha, or similar)

Week 1: Introduction to TypeScript & Setting Up a TDD Workflow

Learning Objectives

  • Understand the benefits of TypeScript over JavaScript
  • Set up a TypeScript project with Jest for TDD
  • Write basic TypeScript with type annotations

Topics Covered

  • What is TypeScript? Why use it?
  • Setting up TypeScript (tsc, tsconfig.json)
  • Installing and configuring Jest with TypeScript
  • Writing and running a basic test in TypeScript
  • Type annotations (number, string, boolean, any, unknown)
  • First TDD cycle: Write a test → Write minimal TypeScript → Refactor

Exercise

  1. Initialize a TypeScript project with Jest.
  2. Write a function add(a, b): number following TDD principles.

Week 2: Functions, Interfaces, and Testing Strategies

Learning Objectives

  • Understand TypeScript’s function signatures and parameter types
  • Learn about interfaces and how they enforce contracts
  • Explore testing strategies for functions and objects

Topics Covered

  • Function signatures (optional, default, rest parameters)
  • Defining and using interfaces
  • Testing pure functions in TypeScript
  • Using tsc --noEmit for type-checking without compilation
  • Error handling and testing edge cases

Exercise

  1. Create an interface for a User object.
  2. Write a function getFullName(user: User): string and test it using TDD.

Week 3: Classes, Enums, and Dependency Injection in TDD

Learning Objectives

  • Learn how to use TypeScript classes
  • Understand enum usage in TypeScript
  • Implement dependency injection for better testability

Topics Covered

  • TypeScript class and constructor parameters
  • Public, private, and readonly properties
  • Using enum for managing constant values
  • Mocking dependencies in unit tests
  • Testing class methods using Jest

Exercise

  1. Create a Logger class with a logMessage(level: LogLevel, message: string) method.
  2. Use TDD to build and test the class.

Week 4: Advanced TypeScript & Real-World TDD Practices

Learning Objectives

  • Explore generics and how they improve code reusability
  • Understand TypeScript’s utility types
  • Learn how to integrate TypeScript and TDD in a real-world project

Topics Covered

  • Generics (T, U, K extends keyof T)
  • TypeScript utility types (Partial<T>, Readonly<T>, Pick<T>)
  • Testing asynchronous code and promises in TypeScript
  • Integrating TypeScript into an existing JavaScript project
  • Using ESLint and Prettier for TypeScript projects

Exercise

  1. Create a fetchData<T>(url: string): Promise<T> function.
  2. Write tests to ensure proper error handling and response parsing.

Final Project

Participants will apply their knowledge by developing a small, test-driven TypeScript application, such as:

  • A simple to-do list with TypeScript classes and interfaces
  • A REST API client with typed responses and unit tests
  • A CLI tool using TypeScript and Node.js

Course Wrap-Up

  • Review key takeaways from TypeScript and TDD
  • Discuss real-world use cases and best practices
  • Provide resources for further learning

Additional Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment