TypeScript: Object with Optional Properties
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
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
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
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
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…
Javascript: Capitalize the First Letter of Each Word (Title Case)
This short article shows you how to capitalize the first letter of each word in a string. hypothetical inputs and expected outputs: we will just capitalize the first letter of a word and keep the rest…
Express + TypeScript: Extending Request and Response objects
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
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
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
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…
React + TypeScript: onMouseOver & onMouseOut events
This article is about the onMouseOver and onMouseOut events in a React project written in TypeScript. We’ll go through the fundamentals of these events then examine a complete example of using them in practice. Overview The…
React + TypeScript: Image onLoad & onError Events
The end-to-end example below shows you how to handle image events in a React app that uses TypeScript. There are 2 events that we are going to work with: onLoad: This event occurs when an image…