
TypeScript 4 Design Patterns and Best Practices
By :

When you declare interfaces and classes in TypeScript, the compiler takes that information and uses it when performing type checks or other assertions. Then at runtime, when the browser or the server evaluates the code, it creates and manages those objects for the duration of the application life cycle. Sometimes you can create objects at the start of the application, for example, you saw the object creation of the Express.js app in the previous chapter:
const app = express();
Other times, you might create objects on the fly using an object descriptor. For example, you saw in Chapter 2, TypeScript Core Principles, how you can create HTML span
elements:
const span = document.createElement("span");
Both of these approaches deal with object creation, and more specifically, how to instantiate a type of object and store it somewhere. If you think about that for a minute, then you will realize there are two distinct phases here: