TypeScript

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

Updated: September 14, 2022 By: 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 Extend Types in TypeScript

Updated: August 16, 2022 By: 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

Updated: March 3, 2023 By: 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)

Updated: March 3, 2023 By: 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

Updated: July 29, 2022 By: 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…

TypeScript: Object with Optional Properties

Updated: April 10, 2022 By: 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…

Using Rest Parameters in TypeScript Functions

Updated: November 17, 2021 By: 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

Updated: November 17, 2021 By: 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…

Express + TypeScript: Extending Request and Response objects

Updated: July 12, 2022 By: Augustus

This article shows you how to add new properties to an Express request object (we often deal with this task when working with middleware) or an Express response (not too common but may be necessary in…

React + TypeScript: Working with Radio Button Groups

Updated: March 3, 2023 By: A Goodman

The end-to-end example below covers the most important aspects you need to know when working with radio button groups in a React application written in TypeScript. We will write code from scratch and use the modern…

React + TypeScript: Making a Custom Context Menu

Updated: March 3, 2023 By: A Goodman

This article walks you through an end-to-end example of creating a custom context menu in a React app that is written in TypeScript. We’ll use new features of React like hooks and functional components. You won’t…

React + TypeScript: Multiple Select example

Updated: March 3, 2023 By: A Goodman

The example below describes how to use a multiple select in a React project written in TypeScript. You will learn to get the selected values as well as display them on the screen. Everything will be…

1 2