Adding Types to Function Parameters in TypeScript

Last updated on 5 Jan, 2023

Here is a normal function in JavaScript:

function add(num1, num2) {
  return num1 + num2;

We can set type for num1 and num2 using a colon.

Here is the equivalent TypeScript code:

function add(num1: number, num2: number) {
  return num1 + num2;
--- ○ ---
Joby Joseph
Web Architect