Backbencher.dev

Add Types to Function Parameters in TypeScript

Last updated on 17 Jan, 2023

We can add types to function parameters using TypeScript.

Here is a function:

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

Let us specify num1 and num2 as number type using TypeScript.

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