TypeScript Cookbook Examples

The TypeScript Cookbook is a collection of over 100 recipes for TypeScript development! Each recipe is a self-contained example that can be used as a reference to help you in your TypeScript journey.

Each example stems from a real-world problem that I've encountered when working alone or with multiple teams.

I strongly believe that you can only learn a programming language if you see the code directly in an editor. Getting a feeling how the compiler, the language server, and your IDE behave when typing is essential to understanding how TypeScript works.

This is why I collect an interactive example for each recipe. You can play with the code, change it, and see how the compiler reacts to your changes. Find links to Codesandbox and the Playground below.

List of Examples

To be extended! Check back regularly!

  1. Generalizing Function Signatures
  2. Creating Related Function Arguments
  3. Getting Rid of any and unknown
  4. Understanding Generic Instantiation
  5. Adding Const Context to Generic Type Parameters
  6. Modifying Nested Objects
  7. Remapping Types
  8. Allowing at Least One Property
  9. Typing Higher-Order Components
  10. Choosing the Right Visibility Modifier
  11. Writing Static Classes
  12. Working with this Types in Classes
  13. Writing Decorators