Node.js + Express + TypeScript: req.query type

September 14, 2022 Snowball

When working with Node and Express.js, there might be cases where you need to access req.query, an object that contains the property for each query string parameter in the route. For example, given a route like…

2 Ways to Merge Objects in TypeScript

August 16, 2022 Snowball

This quick article shows you 2 different approaches to merging 2 or more objects in TypeScript. Without any further ado, let’s get our hands dirty. Using the spread operator There are some important things you need…

2 Ways to Extend Types in TypeScript

August 16, 2022 Snowball

This short and straightforward article shows you a couple of different ways to extend a type in TypeScript. Without any further ado, let’s see the code. Using the “extends” keyword Example: Using the “&” operator Example:…

React + TypeScript: Using setTimeout() with Hooks

August 15, 2022 A Goodman

This succinct, practical article walks you through a complete example of using the window.setTimeout() and window.clearTimeout() methods in a React application that is written in TypeScript. We’ll use functional components with hooks (useState, useEffect, and useRef)….

React + TypeScript: setInterval() example (with hooks)

August 15, 2022 A Goodman

This practical article walks you through a complete example of using the window.setInterval() method in combination with hooks (useState, useEffect, and useRef) in a React application that is written in TypeScript. No more rambling; let’s unveil…

TypeScript: Tuple Examples

July 29, 2022 Augustus

In TypeScript, a tuple is a specific type of array which has the following characteristics: The number and order of elements are fixed and must be adhered The type of each element is predefined and strict…

VS Code: Set Preferred Quote Type for Quick Fixes

July 27, 2022 A Goodman

When working with Javascript and TypeScript, arbitrary use of single quotes and double quotes may not cause errors but will result in a lack of consistency and readability. Therefore, choosing and going with a certain quote…

TypeScript: Object with Optional Properties

April 10, 2022 Pennywise

In TypeScript, you can specify that some or all properties of an object are optional. To do so, just add a question mark (?) after the property name. Example: Output: Further reading: TypeScript: Using Variables to…

TypeScript: Using Variables to Set Object Keys

March 20, 2022 Hadrianus

There might be cases where you want to use a variable as a dynamic key of an object in TypeScript. The following examples will show you how to do that. Example 1 Output: Example 2 Output:…

Using Rest Parameters in TypeScript Functions

November 17, 2021 A Goodman

In TypeScript, you can use the spread operator (…) as the final parameter of a function. All of the arguments (except the ones that were explicitly declared before the three dots) passed to that function will…

TypeScript: Function with Optional and Default Parameters

November 17, 2021 A Goodman

In TypeScript, a function can have optional and default parameters. In order to make a parameter optional, we can postfix it with a question mark (?). We can provide a default value to a parameter by…

Calculate Variance and Standard Deviation in Javascript

November 15, 2021 Napoleon

This short article shows you how to calculate the variance and standard deviation of a given array of numbers. You will see the code in vanilla Javascript and TypeScript. Javascript Output: TypeScript If you use TypeScript…

1 2 3