One of the more obscure features of JavaScript and TypeScript is the generator function. Many developers have heard about or used it without knowing it, but those who understand it are rare. The generator function goes hand in hand [...]
If you come from a C# background, you may want to add multiple constructors to a TypeScript class. Although TypeScript doesn't support multiple constructors, you can still achieve similar behavior.
In TypeScript, you can achieve a similar behavior to [...]
Sometimes, a TypeScript developer may want to add a global variable to the code base. Luckily, this is easy to do.
To add a new global variable to TypeScript, you can:
Augment the global object (when running in a [...]
When preparing for a coding interview, you may have encountered the queue data structure and wanted to implement it in a TypeScript project. Luckily, this is easy to do.
The queue data structure is a list of elements that [...]
When using object-oriented programming concepts in TypeScript, often a developer needs to make a class implement an interface. Luckily, this is easy to do.
To make a class implement an interface in TypeScript, you need to use the special [...]
To create a read-only property in TypeScript, you need to use the readonly keyword.
Here is an example of a read-only property inside an interface:
interface IPerson {
readonly name: string;
role: string;
}
This article explains everything about [...]
TypeScript offers multiple loop types to iterate through a piece of code. Some are well known and used a lot, like the for loop. Others are less used, like the while loop.
The while loop runs some code while [...]
Enums are useful when you have a fixed set of constants. Sometimes, a developer needs to transform a TypeScript enum into an array. Luckily, this is easy to do.
To transform an enum into an array in TypeScript, you [...]
In TypeScript, arrays are one of the most useful data structures. They can store a collection of values of any data type. Sometimes, a developer might need to get the last element of an array. Luckily, it is easy [...]
When developing a web application or TypeScript library, a developer may need to initialize an empty typed object. Luckily, it is easy to achieve.
To initialize an empty typed object in TypeScript, you can:
Use type assertion
Create a [...]