When using TypeScript, developers often need to replace placeholders with values inside a string. This operation is called string interpolation.
To perform string interpolation in TypeScript, create a template literal like so:
const age = 20;
console.log(`Your age [...]
Nowadays, an arrow function is the default and easiest way to define a function in TypeScript and JavaScript. But how does it work exactly?
Here is an example of an arrow function in TypeScript:
const sum = (x: number [...]
Sometimes, a TypeScript developer wants to make an arrow function accept different types. That's where generic functions come into play.
To make an arrow function generic, you need to add a generic parameter to it like this:
const getX [...]
If you are writing TypeScript code long enough, you have seen the declare keyword. But what does it do, and why use it?
The declare keyword tells the TypeScript compiler that an object exists AND can be used inside [...]
Often, a TypeScript developer needs to define an array of objects. Luckily, this is easy to achieve.
In TypeScript, to define an array of objects, you can:
Use an existing type or interface.
Use an inline type.
Use the [...]
When working on a TypeScript project, a developer sometimes needs to modify an existing interface by adding one or more members. Luckily, this is easy to do.
To extend an interface in TypeScript, you must use the extends keyword [...]
If you've been writing TypeScript code for long enough, you've undoubtedly seen occurrences of the double question mark operator.
The double question mark operator or nullish coalescing operator helps assign a default value to a null or undefined TypeScript [...]
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 [...]