Skip to main content

17 docs tagged with "design-patterns"

View all tags

Decorator — A Pattern Distinct from TC39 Decorators

Despite the shared name, GoF's Decorator pattern and TypeScript's Decorators syntax are different concepts. This chapter separates the two, then compares the pattern with composition through higher-order functions.

Singleton — How Far a Module's Single Instance Reaches

An ES module is evaluated only once as long as it resolves to the same URL, so you get a single instance without writing a Singleton class. This chapter maps how far that guarantee reaches and when you still need another approach.

Strategy — Functions Being First-Class

If all you do is swap behavior, passing a function is enough. What still makes you want to bundle things into an object is a strategy that carries several methods or state.

TypeScript Design Patterns

A 16-chapter guide that rereads the 23 GoF patterns in modern TypeScript. Each chapter judges whether language features can replace the pattern, and lays out the conditions under which writing it as a class still pays off.