SitePoint
Blog
Forum
Library
Login
Join Premium
Toggle sidebar
TypeScript 4 Design Patterns and Best Practices
Toggle community discussions
Close
Content
Files
Bookmarks
Preface
TypeScript 4 Design Patterns and Best Practices
Contributors
About the author
About the reviewer
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Share your thoughts
1
Getting Started with TypeScript 4
Section 1: Getting Started with TypeScript 4
Technical requirements
Introducing TypeScript 4
Working with input and output
Useful TypeScript 4 features
Understanding TypeScript and JavaScript's relationship
How does JavaScript compare to TypeScript?
Transitioning from JavaScript to TypeScript
Design patterns in JavaScript
Installing and using the code examples
Reviewing the libraries included in the code examples
Understanding the tsconfig.json file
Running the unit tests
Using VSCode with TypeScript
Using VSCode for this book's code
Inspecting types
Refactoring with VSCode
Introducing Unified Modeling Language (UML)
What is UML?
Learning UML class diagrams
Summary
Q & A
Further reading
TypeScript Core Principles
Technical requirements
Working with advanced types
Using utility types
Using advanced types and assertions
OOP with TypeScript
Abstraction
Inheritance
Encapsulation
Polymorphism
Developing in the browser
Understanding the DOM
Using TypeScript with webpack
Using React
Developing in the server
Understanding the server environment
Using Express with TypeScript
Introducing design patterns in TypeScript
Why design patterns exist
Design patterns in TypeScript
Summary
Q&A
Further reading
Creational Design Patterns
Section 2: Core Design Patterns and Concepts
Technical requirements
Creational design patterns
Singleton pattern
When do we use the Singleton?
UML class diagram
Classic implementation
Modern implementations
Variants
Testing
Criticisms of the singleton
Real-world examples
Prototype pattern
When do we use the Prototype pattern?
UML class diagram
Classic implementation
Testing
Criticisms of the Prototype pattern
Real-world examples
Builder pattern
When do we use Builder?
UML class diagram for Builder
Classic implementation
Testing
Modern implementations
Criticisms of Builder
Real-world examples
Factory method pattern
When do we use the Factory method?
UML class diagram
Classic implementation
Alternative implementations
Testing
Real-world examples
Abstract Factory pattern
When do we use the Abstract Factory?
UML class diagram
Classic implementation
Testing
Criticisms of Abstract Factory
Real-world example
Summary
Q&A
Further reading
Structural Design Patterns
Technical requirements
Understanding structural design patterns
Adapter pattern
When to use Adapter
UML class diagram
Classic implementation
Testing
Criticisms of Adapter
Real-world use cases
Decorator pattern
When to use Decorator
UML class diagram
Classic implementation
Modern variants
Testing
Criticisms of Decorator
Real-world use cases
Façade pattern
When to use Façade
UML class diagram
Classic implementation
Testing
Criticisms of Façade
Real-world use cases
Composite pattern
When to use Composite
UML class diagram
Classic implementation
Testing
Criticisms of Composite
Real-world use cases
Proxy pattern
When to use Proxy
UML class diagram
Classic implementation
Modern variant
Testing
Criticisms of Proxy
Real-world use cases
Bridge pattern
When to use Bridge
UML class diagram
Classic implementation
Testing
Criticisms of Bridge
Real-world use cases
Flyweight pattern
When to use Flyweight
UML class diagram
Classic implementation
Testing
Criticisms of Flyweight
Real-world use cases
Summary
Q&A
Further reading
Behavioral Design Patterns
Technical requirements
Behavioral design patterns
The Strategy pattern?
When to use the Strategy pattern
UML class diagram
Classic implementation
Testing
Criticism of this pattern
Real-world use cases
Chain of Responsibility
When to use Chain of Responsibility?
UML class diagram
Classic implementation
Testing
Criticisms of this pattern
Real-world use case
The Command pattern
When to use the Command pattern?
UML class diagram
Classic implementation
Testing
Criticism of this pattern
Real-world use case
The Iterator pattern
When to use the Iterator pattern?
UML class diagram
Classic implementation
Testing
Criticism of this pattern
Real-world use case
The Mediator pattern
When to use the Meditator pattern?
UML class diagram
Classic implementation
Testing
Criticisms of this pattern
Real-world use cases
The Observer pattern
When to use the Observer pattern?
UML class diagram
Classic implementation
Testing
Criticisms of this pattern
Real-world use case
The Memento pattern
When to use the Memento pattern?
UML class diagram
Classic implementation
Testing
Criticisms of this pattern
Real-world use case
The State pattern
When to use the State pattern?
UML class diagram
Classic implementation
Testing
Criticisms of this pattern
Real-world use case
The Template method pattern
When to use the Template method pattern?
UML class diagram
Classic implementation
Testing
Criticism of this pattern
Real-world use case
The Visitor pattern
When to use the Visitor pattern?
UML class diagram
Classic implementation
Testing
Criticisms of this pattern
Real-world use case
Summary
Q&A
Further reading
Functional Programming with TypeScript
Section 3: Advanced Concepts and Best Practices
Technical requirements
Learning key concepts in functional programming
Pure functions
Recursion
Functions as first-class citizens
Function composition
Referential transparency
Immutability
Understanding functional lenses
Implementation of lenses
Use cases of lenses
Understanding transducers
Understanding monads
Summary
Q & A
Further reading
Reactive Programming with TypeScript
Technical requirements
Learning Reactive programming concepts
The asynchronous propagation of changes
The pull pattern
The push pattern
The push-pull pattern
Understanding Promises and Futures
Futures
Learning observables
Getting started with ReactiveX observables
Composable operators
Cold versus hot observables
Summary
Q & A
Further reading
Developing Modern and Robust TypeScript Applications
Technical requirements
Combining patterns
Singleton
Iterator
Command
Using utility types
Using domain-driven design
Understanding entities
Understanding value objects
Understanding domain events
Applying the SOLID principles
Understanding the single-responsibility principle
Understanding the open-closed principle
Understanding the Liskov substitution principle
Understanding the interface segregation principle
Understanding the dependency inversion principle
Is using SOLID a best practice?
Summary
Q&A
Further reading
Anti-Patterns and Workarounds
Technical requirements
Class overuse
Not using runtime assertions
Permissive or incorrect types
Using idiomatic code from other languages
From the Java language
From the Go language
Type inference gotchas
Summary
Q & A
Further reading
Share your thoughts
Open text modal
Community Questions
Close