What if your functions could warn you before you make a mistake with the wrong input?
Why Parameters type in Typescript? - Purpose & Use Cases
Imagine you are writing a function that takes some inputs, but you don't specify what kind of inputs it should accept. You just write the code and hope the user passes the right values.
For example, a function that adds two numbers but you don't say they must be numbers.
Without telling the function what types of inputs to expect, mistakes happen easily. Someone might pass a word instead of a number, and your program breaks or gives wrong answers.
It becomes hard to find these errors because the code doesn't clearly say what it needs.
By using parameter types, you tell the function exactly what kind of inputs it should get. This helps catch mistakes early, before running the program.
It also makes your code easier to understand and safer to use.
function add(a, b) {
return a + b;
}function add(a: number, b: number): number {
return a + b;
}It enables writing clear, safe functions that catch input mistakes early and help others understand how to use them correctly.
Think of a calculator app that only works if you enter numbers. Parameter types make sure the calculator never tries to add words or other wrong inputs.
Parameter types tell functions what inputs to expect.
This prevents errors by catching wrong inputs early.
It makes code clearer and safer to use.