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. Generating New Object Types
  6. Adding Const Context to Generic Type Parameters
  7. Modifying Nested Objects
  8. Remapping Types
  9. Allowing at Least One Property
  10. Typing Higher-Order Components
  11. Choosing the Right Visibility Modifier
  12. Writing Static Classes
  13. Working with this Types in Classes
  14. Writing Decorators