In TypeScript, function parameters should have type annotations. This makes sure you don’t pass the wrong type of value to a function.
Example:
// 👇 :string is a type annotation
function greet(firstName: string) {
return "Hello " + firstName;
}
One of TypeScript’s biggest benefits is catching errors before you run your code.
Here’s a classic example: a function expects a number, but you accidentally pass a string. In JavaScript, this might run but give wrong results. In TypeScript, you get an error right away.
double that takes a parameter n of type number and returns n * 2.