Skip to content

mildronize/type-safe-design-pattern

Repository files navigation

Type-safe Design Pattern in Modern TypeScript

This book provide ready to use design pattern for type-safe approach in modern typescript by Thada Wangthammang

Table of Contents

  • TypeScript Config
    • Use strict
  • Data Structure
    • Use literal type rathen than string
    • Use Record object rather than list/array
    • Use Tuple rather than list/array
  • Design Patterns
    • Use builder pattern
    • Use function argument instead of plain object
    • Use function overload

Prerequisites

Please make sure you have a good understanding of TypeScript before reading this book. If you are new to TypeScript, I recommend reading the TypeScript Handbook first.

Generics are a fundamental concept in TypeScript, so make sure you understand them. You can read the Generics section of the TypeScript Handbook.

After that, make sure you have understand type-level programming. You can read the Type-Level Programming book. There are many free chapters available. However, I recommend buying the book to support the author.

Disclaimer

I did not create these design patterns. I learned from various modern TypeScript open-source projects, including famous ones like Zod, tRPC, Hono, Elysia, and many others, as well as writing the Nammtham (Azure Functions Framework). This process has helped me distill commonly used patterns.

The type-safe design patterns is not suitable for every project. It is intended for projects that require high code quality and design. Make sure to evaluate whether these patterns are suitable for your project before using them.

Contributing

If you have any suggestions or feedback, please feel free to open an issue or submit a pull request on GitHub

License

This book is licensed under the CC BY-NC-ND 4.0

About

Type-safe Design Pattern in Modern TypeScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published