Overview - Type annotation on function parameters
What is it?
Type annotation on function parameters means telling TypeScript what kind of data each input to a function should be. It helps the computer check if you are using the function correctly by making sure the inputs match the expected types. This is done by adding a colon and a type name after each parameter in the function definition. It makes your code safer and easier to understand.
Why it matters
Without type annotations on function parameters, you might accidentally pass wrong data to functions, causing bugs that are hard to find. Type annotations act like a safety net, catching mistakes early before the program runs. This saves time and frustration, especially in bigger projects where many people work on the same code. It also helps tools give better suggestions and warnings while you write code.
Where it fits
Before learning type annotations on function parameters, you should know basic TypeScript syntax and how functions work in JavaScript or TypeScript. After this, you can learn about return type annotations, advanced types like union and intersection types, and how to use interfaces or type aliases to describe complex parameter shapes.